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/elf32-cris.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* CRIS-specific support for 32-bit ELF.
    2    Copyright 2000, 2001 Free Software Foundation, Inc.
     2   Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
    33   Contributed by Axis Communications AB.
    44   Written by Hans-Peter Nilsson, based on elf32-fr30.c
    5 
    6 This file is part of BFD, the Binary File Descriptor library.
    7 
    8 This program is free software; you can redistribute it and/or modify
    9 it under the terms of the GNU General Public License as published by
    10 the Free Software Foundation; either version 2 of the License, or
    11 (at your option) any later version.
    12 
    13 This program is distributed in the hope that it will be useful,
    14 but WITHOUT ANY WARRANTY; without even the implied warranty of
    15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16 GNU General Public License for more details.
    17 
    18 You should have received a copy of the GNU General Public License
    19 along with this program; if not, write to the Free Software
    20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
     5   PIC and shlib bits based primarily on elf32-m68k.c and elf32-i386.c.
     6
     7   This file is part of BFD, the Binary File Descriptor library.
     8
     9   This program is free software; you can redistribute it and/or modify
     10   it under the terms of the GNU General Public License as published by
     11   the Free Software Foundation; either version 2 of the License, or
     12   (at your option) any later version.
     13
     14   This program is distributed in the hope that it will be useful,
     15   but WITHOUT ANY WARRANTY; without even the implied warranty of
     16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17   GNU General Public License for more details.
     18
     19   You should have received a copy of the GNU General Public License
     20   along with this program; if not, write to the Free Software
     21   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    2122
    2223#include "bfd.h"
     
    3132
    3233static void cris_info_to_howto_rela
    33   PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
    34 
    35 static boolean cris_elf_relocate_section
     34  PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
     35
     36static bfd_boolean cris_elf_grok_prstatus
     37  PARAMS ((bfd *abfd, Elf_Internal_Note *note));
     38
     39static bfd_boolean cris_elf_grok_psinfo
     40  PARAMS ((bfd *abfd, Elf_Internal_Note *note));
     41
     42static bfd_boolean cris_elf_relocate_section
    3643  PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
    3744           Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
     
    4148           Elf_Internal_Rela *, bfd_vma));
    4249
    43 static boolean cris_elf_gc_sweep_hook
     50static bfd_boolean cris_elf_gc_sweep_hook
    4451  PARAMS ((bfd *, struct bfd_link_info *, asection *,
    4552           const Elf_Internal_Rela *));
    4653
    4754static asection * cris_elf_gc_mark_hook
    48   PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
     55  PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
    4956           struct elf_link_hash_entry *, Elf_Internal_Sym *));
    5057
    51 static boolean cris_elf_object_p PARAMS ((bfd *));
    52 
    53 static void cris_elf_final_write_processing PARAMS ((bfd *, boolean));
    54 
    55 static boolean cris_elf_print_private_bfd_data PARAMS ((bfd *, PTR));
    56 
    57 static boolean cris_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
     58static bfd_boolean cris_elf_object_p PARAMS ((bfd *));
     59
     60static void cris_elf_final_write_processing PARAMS ((bfd *, bfd_boolean));
     61
     62static bfd_boolean cris_elf_print_private_bfd_data PARAMS ((bfd *, PTR));
     63
     64static bfd_boolean cris_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
     65
     66struct elf_cris_link_hash_entry;
     67static bfd_boolean elf_cris_discard_excess_dso_dynamics
     68  PARAMS ((struct elf_cris_link_hash_entry *, PTR));
     69static bfd_boolean elf_cris_discard_excess_program_dynamics
     70  PARAMS ((struct elf_cris_link_hash_entry *, PTR));
     71static bfd_boolean elf_cris_adjust_gotplt_to_got
     72  PARAMS ((struct elf_cris_link_hash_entry *, PTR));
     73static bfd_boolean elf_cris_try_fold_plt_to_got
     74  PARAMS ((struct elf_cris_link_hash_entry *, PTR));
     75static struct bfd_hash_entry *elf_cris_link_hash_newfunc
     76  PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
     77static struct bfd_link_hash_table *elf_cris_link_hash_table_create
     78  PARAMS ((bfd *));
     79static bfd_boolean elf_cris_adjust_dynamic_symbol
     80  PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
     81static bfd_boolean cris_elf_check_relocs
     82  PARAMS ((bfd *, struct bfd_link_info *, asection *,
     83           const Elf_Internal_Rela *));
     84
     85static bfd_boolean elf_cris_size_dynamic_sections
     86  PARAMS ((bfd *, struct bfd_link_info *));
     87static bfd_boolean elf_cris_finish_dynamic_symbol
     88  PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
     89           Elf_Internal_Sym *));
     90static bfd_boolean elf_cris_finish_dynamic_sections
     91  PARAMS ((bfd *, struct bfd_link_info *));
     92static void elf_cris_hide_symbol
     93  PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, bfd_boolean));
     94static enum elf_reloc_type_class elf_cris_reloc_type_class
     95  PARAMS ((const Elf_Internal_Rela *));
    5896
    5997static reloc_howto_type cris_elf_howto_table [] =
     
    64102         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    65103         32,                    /* bitsize */
    66          false,                 /* pc_relative */
     104         FALSE,                 /* pc_relative */
    67105         0,                     /* bitpos */
    68106         complain_overflow_bitfield, /* complain_on_overflow */
    69107         bfd_elf_generic_reloc, /* special_function */
    70108         "R_CRIS_NONE",         /* name */
    71          false,                 /* partial_inplace */
     109         FALSE,                 /* partial_inplace */
    72110         0,                     /* src_mask */
    73111         0,                     /* dst_mask */
    74          false),                /* pcrel_offset */
     112         FALSE),                /* pcrel_offset */
    75113
    76114  /* An 8 bit absolute relocation.  */
     
    79117         0,                     /* size (0 = byte, 1 = short, 2 = long) */
    80118         8,                     /* bitsize */
    81          false,                 /* pc_relative */
     119         FALSE,                 /* pc_relative */
    82120         0,                     /* bitpos */
    83121         complain_overflow_bitfield, /* complain_on_overflow */
    84122         bfd_elf_generic_reloc, /* special_function */
    85123         "R_CRIS_8",            /* name */
    86          false,                 /* partial_inplace */
     124         FALSE,                 /* partial_inplace */
    87125         0x0000,                /* src_mask */
    88126         0x00ff,                /* dst_mask */
    89          false),                /* pcrel_offset */
     127         FALSE),                /* pcrel_offset */
    90128
    91129  /* A 16 bit absolute relocation.  */
     
    94132         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    95133         16,                    /* bitsize */
    96          false,                 /* pc_relative */
     134         FALSE,                 /* pc_relative */
    97135         0,                     /* bitpos */
    98136         complain_overflow_bitfield, /* complain_on_overflow */
    99137         bfd_elf_generic_reloc, /* special_function */
    100138         "R_CRIS_16",           /* name */
    101          false,                 /* partial_inplace */
     139         FALSE,                 /* partial_inplace */
    102140         0x00000000,            /* src_mask */
    103141         0x0000ffff,            /* dst_mask */
    104          false),                /* pcrel_offset */
     142         FALSE),                /* pcrel_offset */
    105143
    106144  /* A 32 bit absolute relocation.  */
     
    109147         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    110148         32,                    /* bitsize */
    111          false,                 /* pc_relative */
     149         FALSE,                 /* pc_relative */
    112150         0,                     /* bitpos */
    113151         complain_overflow_bitfield, /* complain_on_overflow */
    114152         bfd_elf_generic_reloc, /* special_function */
    115153         "R_CRIS_32",           /* name */
    116          false,                 /* partial_inplace */
     154         FALSE,                 /* partial_inplace */
    117155         0x00000000,            /* src_mask */
    118156         0xffffffff,            /* dst_mask */
    119          false),                /* pcrel_offset */
    120 
    121   /* An 8 bit absolute relocation.  */
     157         FALSE),                /* pcrel_offset */
     158
     159  /* An 8 bit PC-relative relocation.  */
    122160  HOWTO (R_CRIS_8_PCREL,        /* type */
    123161         0,                     /* rightshift */
    124162         0,                     /* size (0 = byte, 1 = short, 2 = long) */
    125163         8,                     /* bitsize */
    126          true,                  /* pc_relative */
     164         TRUE,                  /* pc_relative */
    127165         0,                     /* bitpos */
    128166         complain_overflow_bitfield, /* complain_on_overflow */
    129167         bfd_elf_generic_reloc, /* special_function */
    130168         "R_CRIS_8_PCREL",      /* name */
    131          false,                 /* partial_inplace */
     169         FALSE,                 /* partial_inplace */
    132170         0x0000,                /* src_mask */
    133171         0x00ff,                /* dst_mask */
    134          false),                /* pcrel_offset */
    135 
    136   /* A 16 bit absolute relocation.  */
     172         TRUE),                 /* pcrel_offset */
     173
     174  /* A 16 bit PC-relative relocation.  */
    137175  HOWTO (R_CRIS_16_PCREL,       /* type */
    138176         0,                     /* rightshift */
    139177         1,                     /* size (0 = byte, 1 = short, 2 = long) */
    140178         16,                    /* bitsize */
    141          true,                  /* pc_relative */
     179         TRUE,                  /* pc_relative */
    142180         0,                     /* bitpos */
    143181         complain_overflow_bitfield, /* complain_on_overflow */
    144182         bfd_elf_generic_reloc, /* special_function */
    145          "R_CRIS_16",           /* name */
    146          false,                 /* partial_inplace */
     183         "R_CRIS_16_PCREL",     /* name */
     184         FALSE,                 /* partial_inplace */
    147185         0x00000000,            /* src_mask */
    148186         0x0000ffff,            /* dst_mask */
    149          false),                /* pcrel_offset */
    150 
    151   /* A 32 bit absolute relocation.  */
     187         TRUE),                 /* pcrel_offset */
     188
     189  /* A 32 bit PC-relative relocation.  */
    152190  HOWTO (R_CRIS_32_PCREL,       /* type */
    153191         0,                     /* rightshift */
    154192         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    155193         32,                    /* bitsize */
    156          true,                  /* pc_relative */
     194         TRUE,                  /* pc_relative */
    157195         0,                     /* bitpos */
    158196         complain_overflow_bitfield, /* complain_on_overflow */
    159197         bfd_elf_generic_reloc, /* special_function */
    160          "R_CRIS_32",           /* name */
    161          false,                 /* partial_inplace */
     198         "R_CRIS_32_PCREL",     /* name */
     199         FALSE,                 /* partial_inplace */
    162200         0x00000000,            /* src_mask */
    163201         0xffffffff,            /* dst_mask */
    164          false),                /* pcrel_offset */
    165 
    166   /* GNU extension to record C++ vtable hierarchy */
    167   HOWTO (R_CRIS_GNU_VTINHERIT, /* type */
     202         TRUE),                 /* pcrel_offset */
     203
     204  /* GNU extension to record C++ vtable hierarchy. */
     205  HOWTO (R_CRIS_GNU_VTINHERIT,  /* type */
    168206         0,                     /* rightshift */
    169207         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    170208         0,                     /* bitsize */
    171          false,                 /* pc_relative */
     209         FALSE,                 /* pc_relative */
    172210         0,                     /* bitpos */
    173211         complain_overflow_dont, /* complain_on_overflow */
    174212         NULL,                  /* special_function */
    175213         "R_CRIS_GNU_VTINHERIT", /* name */
    176          false,                 /* partial_inplace */
     214         FALSE,                 /* partial_inplace */
    177215         0,                     /* src_mask */
    178216         0,                     /* dst_mask */
    179          false),                /* pcrel_offset */
    180 
    181   /* GNU extension to record C++ vtable member usage */
    182   HOWTO (R_CRIS_GNU_VTENTRY,     /* type */
     217         FALSE),                /* pcrel_offset */
     218
     219  /* GNU extension to record C++ vtable member usage. */
     220  HOWTO (R_CRIS_GNU_VTENTRY,    /* type */
    183221         0,                     /* rightshift */
    184222         2,                     /* size (0 = byte, 1 = short, 2 = long) */
    185223         0,                     /* bitsize */
    186          false,                 /* pc_relative */
     224         FALSE,                 /* pc_relative */
    187225         0,                     /* bitpos */
    188226         complain_overflow_dont, /* complain_on_overflow */
    189227         _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
    190228         "R_CRIS_GNU_VTENTRY",   /* name */
    191          false,                 /* partial_inplace */
     229         FALSE,                 /* partial_inplace */
    192230         0,                     /* src_mask */
    193231         0,                     /* dst_mask */
    194          false)                 /* pcrel_offset */
     232         FALSE),                /* pcrel_offset */
     233
     234  /* This is used only by the dynamic linker.  The symbol should exist
     235     both in the object being run and in some shared library.  The
     236     dynamic linker copies the data addressed by the symbol from the
     237     shared library into the object, because the object being
     238     run has to have the data at some particular address.  */
     239  HOWTO (R_CRIS_COPY,           /* type */
     240         0,                     /* rightshift */
     241         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     242         32,                    /* bitsize */
     243         FALSE,                 /* pc_relative */
     244         0,                     /* bitpos */
     245         complain_overflow_bitfield, /* complain_on_overflow */
     246         bfd_elf_generic_reloc, /* special_function */
     247         "R_CRIS_COPY",         /* name */
     248         FALSE,                 /* partial_inplace */
     249         0,                     /* src_mask */
     250         0,                     /* dst_mask */
     251         FALSE),                /* pcrel_offset */
     252
     253  /* Like R_CRIS_32, but used when setting global offset table entries.  */
     254  HOWTO (R_CRIS_GLOB_DAT,       /* type */
     255         0,                     /* rightshift */
     256         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     257         32,                    /* bitsize */
     258         FALSE,                 /* pc_relative */
     259         0,                     /* bitpos */
     260         complain_overflow_bitfield, /* complain_on_overflow */
     261         bfd_elf_generic_reloc, /* special_function */
     262         "R_CRIS_GLOB_DAT",     /* name */
     263         FALSE,                 /* partial_inplace */
     264         0,                     /* src_mask */
     265         0xffffffff,            /* dst_mask */
     266         FALSE),                /* pcrel_offset */
     267
     268  /* Marks a procedure linkage table entry for a symbol.  */
     269  HOWTO (R_CRIS_JUMP_SLOT,      /* type */
     270         0,                     /* rightshift */
     271         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     272         32,                    /* bitsize */
     273         FALSE,                 /* pc_relative */
     274         0,                     /* bitpos */
     275         complain_overflow_bitfield, /* complain_on_overflow */
     276         bfd_elf_generic_reloc, /* special_function */
     277         "R_CRIS_JUMP_SLOT",    /* name */
     278         FALSE,                 /* partial_inplace */
     279         0,                     /* src_mask */
     280         0,                     /* dst_mask */
     281         FALSE),                /* pcrel_offset */
     282
     283  /* Used only by the dynamic linker.  When the object is run, this
     284     longword is set to the load address of the object, plus the
     285     addend.  */
     286  HOWTO (R_CRIS_RELATIVE,       /* 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         bfd_elf_generic_reloc, /* special_function */
     294         "R_CRIS_RELATIVE",     /* name */
     295         FALSE,                 /* partial_inplace */
     296         0,                     /* src_mask */
     297         0xffffffff,            /* dst_mask */
     298         FALSE),                /* pcrel_offset */
     299
     300  /* Like R_CRIS_32, but referring to the GOT table entry for the symbol.  */
     301  HOWTO (R_CRIS_16_GOT,         /* type */
     302         0,                     /* rightshift */
     303         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     304         16,                    /* bitsize */
     305         FALSE,                 /* pc_relative */
     306         0,                     /* bitpos */
     307         complain_overflow_bitfield, /* complain_on_overflow */
     308         bfd_elf_generic_reloc, /* special_function */
     309         "R_CRIS_16_GOT",       /* name */
     310         FALSE,                 /* partial_inplace */
     311         0,                     /* src_mask */
     312         0xffff,                /* dst_mask */
     313         FALSE),                /* pcrel_offset */
     314
     315  HOWTO (R_CRIS_32_GOT,         /* type */
     316         0,                     /* rightshift */
     317         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     318         32,                    /* bitsize */
     319         FALSE,                 /* pc_relative */
     320         0,                     /* bitpos */
     321         complain_overflow_bitfield, /* complain_on_overflow */
     322         bfd_elf_generic_reloc, /* special_function */
     323         "R_CRIS_32_GOT",       /* name */
     324         FALSE,                 /* partial_inplace */
     325         0,                     /* src_mask */
     326         0xffffffff,            /* dst_mask */
     327         FALSE),                /* pcrel_offset */
     328
     329  /* Like R_CRIS_32_GOT, but referring to (and requesting a) PLT part of
     330     the GOT table for the symbol.  */
     331  HOWTO (R_CRIS_16_GOTPLT,      /* type */
     332         0,                     /* rightshift */
     333         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     334         16,                    /* bitsize */
     335         FALSE,                 /* pc_relative */
     336         0,                     /* bitpos */
     337         complain_overflow_bitfield, /* complain_on_overflow */
     338         bfd_elf_generic_reloc, /* special_function */
     339         "R_CRIS_16_GOTPLT",    /* name */
     340         FALSE,                 /* partial_inplace */
     341         0,                     /* src_mask */
     342         0xffff,                /* dst_mask */
     343         FALSE),                /* pcrel_offset */
     344
     345  HOWTO (R_CRIS_32_GOTPLT,      /* type */
     346         0,                     /* rightshift */
     347         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     348         32,                    /* bitsize */
     349         FALSE,                 /* pc_relative */
     350         0,                     /* bitpos */
     351         complain_overflow_bitfield, /* complain_on_overflow */
     352         bfd_elf_generic_reloc, /* special_function */
     353         "R_CRIS_32_GOTPLT",    /* name */
     354         FALSE,                 /* partial_inplace */
     355         0,                     /* src_mask */
     356         0xffffffff,            /* dst_mask */
     357         FALSE),                /* pcrel_offset */
     358
     359  /* A 32-bit offset from GOT to (local const) symbol: no GOT entry should
     360     be necessary.  */
     361  HOWTO (R_CRIS_32_GOTREL,      /* type */
     362         0,                     /* rightshift */
     363         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     364         32,                    /* bitsize */
     365         FALSE,                 /* pc_relative */
     366         0,                     /* bitpos */
     367         complain_overflow_bitfield, /* complain_on_overflow */
     368         bfd_elf_generic_reloc, /* special_function */
     369         "R_CRIS_32_GOTREL",    /* name */
     370         FALSE,                 /* partial_inplace */
     371         0,                     /* src_mask */
     372         0xffffffff,            /* dst_mask */
     373         FALSE),                /* pcrel_offset */
     374
     375  /* A 32-bit offset from GOT to entry for this symbol in PLT and request
     376     to create PLT entry for symbol.  */
     377  HOWTO (R_CRIS_32_PLT_GOTREL,  /* type */
     378         0,                     /* rightshift */
     379         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     380         32,                    /* bitsize */
     381         FALSE,                 /* pc_relative */
     382         0,                     /* bitpos */
     383         complain_overflow_bitfield, /* complain_on_overflow */
     384         bfd_elf_generic_reloc, /* special_function */
     385         "R_CRIS_32_PLT_GOTREL", /* name */
     386         FALSE,                 /* partial_inplace */
     387         0,                     /* src_mask */
     388         0xffffffff,            /* dst_mask */
     389         FALSE),                /* pcrel_offset */
     390
     391  /* A 32-bit offset from PC (location after the relocation) + addend to
     392     entry for this symbol in PLT and request to create PLT entry for
     393     symbol.  */
     394  HOWTO (R_CRIS_32_PLT_PCREL,   /* type */
     395         0,                     /* rightshift */
     396         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     397         32,                    /* bitsize */
     398         TRUE,                  /* pc_relative */
     399         0,                     /* bitpos */
     400         complain_overflow_bitfield, /* complain_on_overflow */
     401         bfd_elf_generic_reloc, /* special_function */
     402         "R_CRIS_32_PLT_PCREL", /* name */
     403         FALSE,                 /* partial_inplace */
     404         0,                     /* src_mask */
     405         0xffffffff,            /* dst_mask */
     406         TRUE)                  /* pcrel_offset */
    195407};
    196408
     
    214426  { BFD_RELOC_32_PCREL,         R_CRIS_32_PCREL },
    215427  { BFD_RELOC_VTABLE_INHERIT,   R_CRIS_GNU_VTINHERIT },
    216   { BFD_RELOC_VTABLE_ENTRY,     R_CRIS_GNU_VTENTRY }
     428  { BFD_RELOC_VTABLE_ENTRY,     R_CRIS_GNU_VTENTRY },
     429  { BFD_RELOC_CRIS_COPY,        R_CRIS_COPY },
     430  { BFD_RELOC_CRIS_GLOB_DAT,    R_CRIS_GLOB_DAT },
     431  { BFD_RELOC_CRIS_JUMP_SLOT,   R_CRIS_JUMP_SLOT },
     432  { BFD_RELOC_CRIS_RELATIVE,    R_CRIS_RELATIVE },
     433  { BFD_RELOC_CRIS_16_GOT,      R_CRIS_16_GOT },
     434  { BFD_RELOC_CRIS_32_GOT,      R_CRIS_32_GOT },
     435  { BFD_RELOC_CRIS_16_GOTPLT,   R_CRIS_16_GOTPLT },
     436  { BFD_RELOC_CRIS_32_GOTPLT,   R_CRIS_32_GOTPLT },
     437  { BFD_RELOC_CRIS_32_GOTREL,   R_CRIS_32_GOTREL },
     438  { BFD_RELOC_CRIS_32_PLT_GOTREL, R_CRIS_32_PLT_GOTREL },
     439  { BFD_RELOC_CRIS_32_PLT_PCREL, R_CRIS_32_PLT_PCREL }
    217440};
    218441
     
    224447  unsigned int i;
    225448
    226   for (i = sizeof (cris_reloc_map) / sizeof (cris_reloc_map[0]);
    227        --i;)
     449  for (i = 0; i < sizeof (cris_reloc_map) / sizeof (cris_reloc_map[0]); i++)
    228450    if (cris_reloc_map [i].bfd_reloc_val == code)
    229451      return & cris_elf_howto_table [cris_reloc_map[i].cris_reloc_val];
     
    238460     bfd * abfd ATTRIBUTE_UNUSED;
    239461     arelent * cache_ptr;
    240      Elf32_Internal_Rela * dst;
     462     Elf_Internal_Rela * dst;
    241463{
    242464  unsigned int r_type;
     
    248470
    249471
     472/* Support for core dump NOTE sections.  */
     473
     474static bfd_boolean
     475cris_elf_grok_prstatus (abfd, note)
     476     bfd *abfd;
     477     Elf_Internal_Note *note;
     478{
     479  int offset;
     480  size_t raw_size;
     481
     482  switch (note->descsz)
     483    {
     484      default:
     485        return FALSE;
     486
     487      case 214:         /* Linux/CRIS */
     488        /* pr_cursig */
     489        elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
     490
     491        /* pr_pid */
     492        elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 22);
     493
     494        /* pr_reg */
     495        offset = 70;
     496        raw_size = 140;
     497
     498        break;
     499    }
     500
     501  /* Make a ".reg/999" section.  */
     502  return _bfd_elfcore_make_pseudosection (abfd, ".reg",
     503                                          raw_size, note->descpos + offset);
     504}
     505
     506static bfd_boolean
     507cris_elf_grok_psinfo (abfd, note)
     508     bfd *abfd;
     509     Elf_Internal_Note *note;
     510{
     511  switch (note->descsz)
     512    {
     513      default:
     514        return FALSE;
     515
     516      case 124:         /* Linux/CRIS elf_prpsinfo */
     517        elf_tdata (abfd)->core_program
     518         = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
     519        elf_tdata (abfd)->core_command
     520         = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
     521    }
     522
     523  /* Note that for some reason, a spurious space is tacked
     524     onto the end of the args in some (at least one anyway)
     525     implementations, so strip it off if it exists.  */
     526
     527  {
     528    char *command = elf_tdata (abfd)->core_command;
     529    int n = strlen (command);
     530
     531    if (0 < n && command[n - 1] == ' ')
     532      command[n - 1] = '\0';
     533  }
     534
     535  return TRUE;
     536}
     537
     538
     539/* The name of the dynamic interpreter.  This is put in the .interp
     540   section.  */
     541
     542#define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
     543
     544/* The size in bytes of an entry in the procedure linkage table.  */
     545
     546#define PLT_ENTRY_SIZE 20
     547
     548/* The first entry in an absolute procedure linkage table looks like this.  */
     549
     550static const bfd_byte elf_cris_plt0_entry[PLT_ENTRY_SIZE] =
     551{
     552  0xfc, 0xe1,
     553  0x7e, 0x7e,   /* push mof.  */
     554  0x7f, 0x0d,   /*  (dip [pc+]) */
     555  0, 0, 0, 0,   /*  Replaced with address of .got + 4.  */
     556  0x30, 0x7a,   /* move [...],mof */
     557  0x7f, 0x0d,   /*  (dip [pc+]) */
     558  0, 0, 0, 0,   /*  Replaced with address of .got + 8.  */
     559  0x30, 0x09,   /* jump [...] */
     560};
     561
     562/* Subsequent entries in an absolute procedure linkage table look like
     563   this.  */
     564
     565static const bfd_byte elf_cris_plt_entry[PLT_ENTRY_SIZE] =
     566{
     567  0x7f, 0x0d,   /*  (dip [pc+]) */
     568  0, 0, 0, 0,   /*  Replaced with address of this symbol in .got.  */
     569  0x30, 0x09,   /* jump [...] */
     570  0x3f,  0x7e,  /* move [pc+],mof */
     571  0, 0, 0, 0,   /*  Replaced with offset into relocation table.  */
     572  0x2f, 0xfe,   /* add.d [pc+],pc */
     573  0xec, 0xff,
     574  0xff, 0xff    /*  Replaced with offset to start of .plt.  */
     575};
     576
     577/* The first entry in a PIC procedure linkage table looks like this.  */
     578
     579static const bfd_byte elf_cris_pic_plt0_entry[PLT_ENTRY_SIZE] =
     580{
     581  0xfc, 0xe1, 0x7e, 0x7e,       /* push mof */
     582  0x04, 0x01, 0x30, 0x7a,       /* move [r0+4],mof */
     583  0x08, 0x01, 0x30, 0x09,       /* jump [r0+8] */
     584  0, 0, 0, 0, 0, 0, 0, 0,       /*  Pad out to 20 bytes.  */
     585};
     586
     587/* Subsequent entries in a PIC procedure linkage table look like this.  */
     588
     589static const bfd_byte elf_cris_pic_plt_entry[PLT_ENTRY_SIZE] =
     590{
     591  0x6f, 0x0d,   /*  (bdap [pc+].d,r0) */
     592  0, 0, 0, 0,   /*  Replaced with offset of this symbol in .got.  */
     593  0x30, 0x09,   /* jump [...] */
     594  0x3f, 0x7e,   /* move [pc+],mof */
     595  0, 0, 0, 0,   /*  Replaced with offset into relocation table.  */
     596  0x2f, 0xfe,   /* add.d [pc+],pc */
     597  0xec, 0xff,   /*  Replaced with offset to start of .plt.  */
     598  0xff, 0xff
     599};
     600
     601
     602/* We copy elf32-m68k.c and elf32-i386.c for the basic linker hash bits
     603   (and most other PIC/shlib stuff).  Check that we don't drift away
     604   without reason.
     605
     606   The CRIS linker, like the m68k and i386 linkers (and probably the rest
     607   too) needs to keep track of the number of relocs that it decides to
     608   copy in check_relocs for each symbol.  This is so that it can discard
     609   PC relative relocs if it doesn't need them when linking with
     610   -Bsymbolic.  We store the information in a field extending the regular
     611   ELF linker hash table.  */
     612
     613/* This structure keeps track of the number of PC relative relocs we have
     614   copied for a given symbol.  */
     615
     616struct elf_cris_pcrel_relocs_copied
     617{
     618  /* Next section.  */
     619  struct elf_cris_pcrel_relocs_copied *next;
     620  /* A section in dynobj.  */
     621  asection *section;
     622  /* Number of relocs copied in this section.  */
     623  bfd_size_type count;
     624};
     625
     626/* CRIS ELF linker hash entry.  */
     627
     628struct elf_cris_link_hash_entry
     629{
     630  struct elf_link_hash_entry root;
     631
     632  /* Number of PC relative relocs copied for this symbol.  */
     633  struct elf_cris_pcrel_relocs_copied *pcrel_relocs_copied;
     634
     635  /* The GOTPLT references are CRIS-specific; the goal is to avoid having
     636     both a general GOT and a PLT-specific GOT entry for the same symbol,
     637     when it is referenced both as a function and as a function pointer.
     638
     639     Number of GOTPLT references for a function.  */
     640  bfd_signed_vma gotplt_refcount;
     641
     642  /* Actual GOTPLT index for this symbol, if applicable, or zero if not
     643     (zero is never used as an index).  FIXME: We should be able to fold
     644     this with gotplt_refcount in a union, like the got and plt unions in
     645     elf_link_hash_entry.  */
     646  bfd_size_type gotplt_offset;
     647};
     648
     649/* CRIS ELF linker hash table.  */
     650
     651struct elf_cris_link_hash_table
     652{
     653  struct elf_link_hash_table root;
     654
     655  /* We can't use the PLT offset and calculate to get the GOTPLT offset,
     656     since we try and avoid creating GOTPLT:s when there's already a GOT.
     657     Instead, we keep and update the next available index here.  */
     658  bfd_size_type next_gotplt_entry;
     659};
     660
     661/* Traverse a CRIS ELF linker hash table.  */
     662
     663#define elf_cris_link_hash_traverse(table, func, info)                  \
     664  (elf_link_hash_traverse                                               \
     665   (&(table)->root,                                                     \
     666    (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
     667    (info)))
     668
     669/* Get the CRIS ELF linker hash table from a link_info structure.  */
     670
     671#define elf_cris_hash_table(p) \
     672  ((struct elf_cris_link_hash_table *) (p)->hash)
     673
     674/* Create an entry in a CRIS ELF linker hash table.  */
     675
     676static struct bfd_hash_entry *
     677elf_cris_link_hash_newfunc (entry, table, string)
     678     struct bfd_hash_entry *entry;
     679     struct bfd_hash_table *table;
     680     const char *string;
     681{
     682  struct elf_cris_link_hash_entry *ret =
     683    (struct elf_cris_link_hash_entry *) entry;
     684
     685  /* Allocate the structure if it has not already been allocated by a
     686     subclass.  */
     687  if (ret == (struct elf_cris_link_hash_entry *) NULL)
     688    ret = ((struct elf_cris_link_hash_entry *)
     689           bfd_hash_allocate (table,
     690                              sizeof (struct elf_cris_link_hash_entry)));
     691  if (ret == (struct elf_cris_link_hash_entry *) NULL)
     692    return (struct bfd_hash_entry *) ret;
     693
     694  /* Call the allocation method of the superclass.  */
     695  ret = ((struct elf_cris_link_hash_entry *)
     696         _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
     697                                     table, string));
     698  if (ret != (struct elf_cris_link_hash_entry *) NULL)
     699    {
     700      ret->pcrel_relocs_copied = NULL;
     701      ret->gotplt_refcount = 0;
     702      ret->gotplt_offset = 0;
     703    }
     704
     705  return (struct bfd_hash_entry *) ret;
     706}
     707
     708/* Create a CRIS ELF linker hash table.  */
     709
     710static struct bfd_link_hash_table *
     711elf_cris_link_hash_table_create (abfd)
     712     bfd *abfd;
     713{
     714  struct elf_cris_link_hash_table *ret;
     715  bfd_size_type amt = sizeof (struct elf_cris_link_hash_table);
     716
     717  ret = ((struct elf_cris_link_hash_table *) bfd_malloc (amt));
     718  if (ret == (struct elf_cris_link_hash_table *) NULL)
     719    return NULL;
     720
     721  if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
     722                                       elf_cris_link_hash_newfunc))
     723    {
     724      free (ret);
     725      return NULL;
     726    }
     727
     728  /* Initialize to skip over the first three entries in the gotplt; they
     729     are used for run-time symbol evaluation.  */
     730  ret->next_gotplt_entry = 12;
     731
     732  return &ret->root.root;
     733}
     734
     735
    250736/* Perform a single relocation.  By default we use the standard BFD
    251    routines, but we might have to do a few relocs ourselves in the future.  */
     737   routines, with a few tweaks.  */
    252738
    253739static bfd_reloc_status_type
     
    261747     bfd_vma             relocation;
    262748{
    263   bfd_reloc_status_type r
    264     = _bfd_final_link_relocate (howto, input_bfd, input_section,
     749  bfd_reloc_status_type r;
     750
     751  /* PC-relative relocations are relative to the position *after*
     752     the reloc.  Note that for R_CRIS_8_PCREL the adjustment is
     753     not a single byte, since PC must be 16-bit-aligned.  */
     754  switch (ELF32_R_TYPE (rel->r_info))
     755    {
     756      /* Check that the 16-bit GOT relocs are positive.  */
     757    case R_CRIS_16_GOTPLT:
     758    case R_CRIS_16_GOT:
     759      if ((bfd_signed_vma) relocation < 0)
     760        return bfd_reloc_overflow;
     761      break;
     762
     763    case R_CRIS_32_PLT_PCREL:
     764    case R_CRIS_32_PCREL:
     765      relocation -= 2;
     766      /* Fall through.  */
     767    case R_CRIS_8_PCREL:
     768    case R_CRIS_16_PCREL:
     769      relocation -= 2;
     770      break;
     771
     772    default:
     773      break;
     774    }
     775
     776  r = _bfd_final_link_relocate (howto, input_bfd, input_section,
    265777                                contents, rel->r_offset,
    266778                                relocation, rel->r_addend);
     
    272784   copied, for further comments.  */
    273785
    274 static boolean
     786static bfd_boolean
    275787cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
    276788                           contents, relocs, local_syms, local_sections)
    277      bfd *                   output_bfd ATTRIBUTE_UNUSED;
    278      struct bfd_link_info *  info;
    279      bfd *                   input_bfd;
    280      asection *              input_section;
    281      bfd_byte *              contents;
    282      Elf_Internal_Rela *     relocs;
    283      Elf_Internal_Sym *      local_syms;
    284      asection **             local_sections;
    285 {
    286   Elf_Internal_Shdr *           symtab_hdr;
    287   struct elf_link_hash_entry ** sym_hashes;
    288   Elf_Internal_Rela *           rel;
    289   Elf_Internal_Rela *           relend;
    290 
     789     bfd *output_bfd ATTRIBUTE_UNUSED;
     790     struct bfd_link_info *info;
     791     bfd *input_bfd;
     792     asection *input_section;
     793     bfd_byte *contents;
     794     Elf_Internal_Rela *relocs;
     795     Elf_Internal_Sym *local_syms;
     796     asection **local_sections;
     797{
     798  bfd *dynobj;
     799  Elf_Internal_Shdr *symtab_hdr;
     800  struct elf_link_hash_entry **sym_hashes;
     801  bfd_vma *local_got_offsets;
     802  asection *sgot;
     803  asection *splt;
     804  asection *sreloc;
     805  Elf_Internal_Rela *rel;
     806  Elf_Internal_Rela *relend;
     807
     808  if (info->relocateable)
     809    return TRUE;
     810
     811  dynobj = elf_hash_table (info)->dynobj;
     812  local_got_offsets = elf_local_got_offsets (input_bfd);
    291813  symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
    292814  sym_hashes = elf_sym_hashes (input_bfd);
    293815  relend     = relocs + input_section->reloc_count;
    294816
    295   /* It seems this can happen with erroneous or unsupported input (mixing
    296      a.out and elf in an archive, for example.)  */
    297   if (sym_hashes == NULL)
    298     return false;
     817  sgot = NULL;
     818  splt = NULL;
     819  sreloc = NULL;
     820
     821  if (dynobj != NULL)
     822    {
     823      splt = bfd_get_section_by_name (dynobj, ".plt");
     824      sgot = bfd_get_section_by_name (dynobj, ".got");
     825    }
    299826
    300827  for (rel = relocs; rel < relend; rel ++)
    301828    {
    302       reloc_howto_type *           howto;
    303       unsigned long                r_symndx;
    304       Elf_Internal_Sym *           sym;
    305       asection *                   sec;
    306       struct elf_link_hash_entry * h;
    307       bfd_vma                      relocation;
    308       bfd_reloc_status_type        r;
    309       const char *                 name = NULL;
    310       int                          r_type;
     829      reloc_howto_type *howto;
     830      unsigned long r_symndx;
     831      Elf_Internal_Sym *sym;
     832      asection *sec;
     833      struct elf_link_hash_entry *h;
     834      bfd_vma relocation;
     835      bfd_reloc_status_type r;
     836      const char *symname = NULL;
     837      int r_type;
    311838
    312839      r_type = ELF32_R_TYPE (rel->r_info);
     
    316843        continue;
    317844
     845      /* This is a final link.  */
    318846      r_symndx = ELF32_R_SYM (rel->r_info);
    319 
    320       if (info->relocateable)
    321         {
    322           /* This is a relocateable link.  We don't have to change
    323              anything, unless the reloc is against a section symbol,
    324              in which case we have to adjust according to where the
    325              section symbol winds up in the output section.  */
    326           if (r_symndx < symtab_hdr->sh_info)
    327             {
    328               sym = local_syms + r_symndx;
    329 
    330               if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
    331                 {
    332                   sec = local_sections [r_symndx];
    333                   rel->r_addend += sec->output_offset + sym->st_value;
    334                 }
    335             }
    336 
    337           continue;
    338         }
    339 
    340       /* This is a final link.  */
    341       howto  = cris_elf_howto_table + ELF32_R_TYPE (rel->r_info);
     847      howto  = cris_elf_howto_table + r_type;
    342848      h      = NULL;
    343849      sym    = NULL;
     
    348854          sym = local_syms + r_symndx;
    349855          sec = local_sections [r_symndx];
    350           relocation = (sec->output_section->vma
    351                         + sec->output_offset
    352                         + sym->st_value);
    353 
    354           name = bfd_elf_string_from_elf_section
    355             (input_bfd, symtab_hdr->sh_link, sym->st_name);
    356           name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
    357 #if 0
    358           fprintf (stderr, "local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n",
    359                    sec->name, name, sym->st_name,
    360                    sec->output_section->vma, sec->output_offset,
    361                    sym->st_value, rel->r_addend);
    362 #endif
     856          relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
     857
     858          symname = (bfd_elf_string_from_elf_section
     859                     (input_bfd, symtab_hdr->sh_link, sym->st_name));
     860          if (symname == NULL)
     861            symname = bfd_section_name (input_bfd, sec);
    363862        }
    364863      else
    365864        {
     865          /* It seems this can happen with erroneous or unsupported input
     866             (mixing a.out and elf in an archive, for example.)  */
     867          if (sym_hashes == NULL)
     868            return FALSE;
     869
    366870          h = sym_hashes [r_symndx - symtab_hdr->sh_info];
    367871
     
    370874            h = (struct elf_link_hash_entry *) h->root.u.i.link;
    371875
    372           name = h->root.root.string;
     876          symname = h->root.root.string;
    373877
    374878          if (h->root.type == bfd_link_hash_defined
     
    376880            {
    377881              sec = h->root.u.def.section;
    378               relocation = (h->root.u.def.value
    379                             + sec->output_section->vma
    380                             + sec->output_offset);
    381 #if 0
    382               fprintf (stderr,
    383                        "defined: sec: %s, name: %s, value: %x + %x + %x gives: %x\n",
    384                        sec->name, name, h->root.u.def.value,
    385                        sec->output_section->vma, sec->output_offset, relocation);
    386 #endif
     882
     883              /* Perhaps we should detect the cases that
     884                 sec->output_section is expected to be NULL like i386 and
     885                 m68k, but apparently (and according to elfxx-ia64.c) all
     886                 valid cases are where the symbol is defined in a shared
     887                 object which we link dynamically against.  This includes
     888                 PLT relocs for which we've created a PLT entry and other
     889                 relocs for which we're prepared to create dynamic
     890                 relocations.
     891
     892                 For now, new situations cause us to just err when
     893                 sec->output_offset is NULL but the object with the symbol
     894                 is *not* dynamically linked against.  Thus this will
     895                 automatically remind us so we can see if there are other
     896                 valid cases we need to revisit.  */
     897              if ((sec->output_section == NULL
     898                   && (sec->owner->flags & DYNAMIC) != 0)
     899
     900                  /* Here follow the cases where the relocation value must
     901                     be zero (or when further handling is simplified when
     902                     zero).  I can't claim to understand the various
     903                     conditions and they weren't described in the files
     904                     where I copied them from (elf32-m68k.c and
     905                     elf32-i386.c), but let's mention examples of where
     906                     they happen.  FIXME: Perhaps define and use a
     907                     dynamic_symbol_p function like ia64.
     908
     909                     - When creating a shared library, we can have an
     910                     ordinary relocation for a symbol defined in a shared
     911                     library (perhaps the one we create).  We then make
     912                     the relocation value zero, as the value seen now will
     913                     be added into the relocation addend in this shared
     914                     library, but must be handled only at dynamic-link
     915                     time.  FIXME: Not sure this example covers the
     916                     h->elf_link_hash_flags test, though it's there in
     917                     other targets.  */
     918                  || (info->shared
     919                      && ((! info->symbolic && h->dynindx != -1)
     920                          || (h->elf_link_hash_flags
     921                              & ELF_LINK_HASH_DEF_REGULAR) == 0)
     922                      && (input_section->flags & SEC_ALLOC) != 0
     923                      && (r_type == R_CRIS_8
     924                          || r_type == R_CRIS_16
     925                          || r_type == R_CRIS_32
     926                          || r_type == R_CRIS_8_PCREL
     927                          || r_type == R_CRIS_16_PCREL
     928                          || r_type == R_CRIS_32_PCREL)))
     929                relocation = 0;
     930              else if (sec->output_section != NULL)
     931                relocation = (h->root.u.def.value
     932                              + sec->output_section->vma
     933                              + sec->output_offset);
     934              else
     935                {
     936                  (*_bfd_error_handler)
     937                    (_("%s: unresolvable relocation %s against symbol `%s' from %s section"),
     938                     bfd_archive_filename (input_bfd),
     939                     cris_elf_howto_table[r_type].name,
     940                     symname,
     941                     bfd_get_section_name (input_bfd, input_section));
     942                  bfd_set_error (bfd_error_bad_value);
     943                  return FALSE;
     944                }
    387945            }
    388946          else if (h->root.type == bfd_link_hash_undefweak)
    389             {
    390 #if 0
    391               fprintf (stderr, "undefined: sec: %s, name: %s\n",
    392                        sec->name, name);
    393 #endif
    394               relocation = 0;
    395             }
     947            relocation = 0;
    396948          else if (info->shared
     949                   && !info->no_undefined
    397950                   && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
    398951            relocation = 0;
    399952          else
    400953            {
    401               if (! ((*info->callbacks->undefined_symbol)
    402                      (info, h->root.root.string, input_bfd,
    403                       input_section, rel->r_offset, true)))
    404                 return false;
    405 #if 0
    406               fprintf (stderr, "unknown: name: %s\n", name);
    407 #endif
     954              if (!(info->callbacks->undefined_symbol
     955                    (info, symname, input_bfd,
     956                     input_section, rel->r_offset,
     957                     (!info->shared || info->no_undefined
     958                      || ELF_ST_VISIBILITY (h->other)))))
     959                return FALSE;
    408960              relocation = 0;
    409961            }
     962        }
     963
     964      switch (r_type)
     965        {
     966        case R_CRIS_16_GOTPLT:
     967        case R_CRIS_32_GOTPLT:
     968          /* This is like the case for R_CRIS_32_GOT and R_CRIS_16_GOT,
     969             but we require a PLT, and the PLT handling will take care of
     970             filling in the PLT-specific GOT entry.  For the GOT offset,
     971             calculate it as we do when filling it in for the .got.plt
     972             section.  If we don't have a PLT, punt to GOT handling.  */
     973          if (h != NULL
     974              && ((struct elf_cris_link_hash_entry *) h)->gotplt_offset != 0)
     975            {
     976              asection *sgotplt
     977                = bfd_get_section_by_name (dynobj, ".got.plt");
     978              bfd_vma got_offset;
     979
     980              BFD_ASSERT (h->dynindx != -1);
     981              BFD_ASSERT (sgotplt != NULL);
     982
     983              got_offset
     984                = ((struct elf_cris_link_hash_entry *) h)->gotplt_offset;
     985
     986              relocation = got_offset;
     987              break;
     988            }
     989
     990          /* We didn't make a PLT entry for this symbol.  Maybe everything is
     991             folded into the GOT.  Other than folding, this happens when
     992             statically linking PIC code, or when using -Bsymbolic.  Check
     993             that we instead have a GOT entry as done for us by
     994             elf_cris_adjust_dynamic_symbol, and drop through into the
     995             ordinary GOT cases.  */
     996          if (h != NULL && h->got.offset == (bfd_vma) -1)
     997            {
     998              (*_bfd_error_handler)
     999                (_("%s: No PLT nor GOT for relocation %s against symbol `%s' from %s section"),
     1000                 bfd_archive_filename (input_bfd),
     1001                 cris_elf_howto_table[r_type].name,
     1002                 symname[0] != '\0' ? symname : _("[whose name is lost]"),
     1003                 bfd_get_section_name (input_bfd, input_section));
     1004
     1005              /* FIXME: Perhaps blaming input is not the right thing to
     1006                 do; this is probably an internal error.  But it is true
     1007                 that we didn't like that particular input.  */
     1008              bfd_set_error (bfd_error_bad_value);
     1009              return FALSE;
     1010            }
     1011          /* Fall through.  */
     1012
     1013          /* The size of the actual relocation is not used here; we only
     1014             fill in the GOT table here.  */
     1015        case R_CRIS_16_GOT:
     1016        case R_CRIS_32_GOT:
     1017          {
     1018            bfd_vma off;
     1019
     1020            /* Note that despite using RELA relocations, the .got contents
     1021               is always filled in with the link-relative relocation
     1022               value; the addend.  */
     1023
     1024            if (h != NULL)
     1025              {
     1026                off = h->got.offset;
     1027                BFD_ASSERT (off != (bfd_vma) -1);
     1028
     1029                if (!elf_hash_table (info)->dynamic_sections_created
     1030                    || (! info->shared
     1031                        && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
     1032                    || (info->shared
     1033                        && (info->symbolic || h->dynindx == -1)
     1034                        && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
     1035                  {
     1036                    /* This wasn't checked above for ! info->shared, but
     1037                       must hold there if we get here; the symbol must be
     1038                       defined in the regular program, or be undefweak.  */
     1039                    BFD_ASSERT (!elf_hash_table (info)->dynamic_sections_created
     1040                                || info->shared
     1041                                || (h->elf_link_hash_flags
     1042                                    & ELF_LINK_HASH_DEF_REGULAR) != 0
     1043                                || h->root.type == bfd_link_hash_undefweak);
     1044
     1045                    /* This is actually a static link, or it is a
     1046                       -Bsymbolic link and the symbol is defined locally,
     1047                       or is undefweak, or the symbol was forced to be
     1048                       local because of a version file, or we're not
     1049                       creating a dynamic object.  We must initialize this
     1050                       entry in the global offset table.  Since the offset
     1051                       must always be a multiple of 4, we use the least
     1052                       significant bit to record whether we have
     1053                       initialized it already.
     1054
     1055                       If this GOT entry should be runtime-initialized, we
     1056                       will create a .rela.got relocation entry to
     1057                       initialize the value.  This is done in the
     1058                       finish_dynamic_symbol routine.  */
     1059                    if ((off & 1) != 0)
     1060                      off &= ~1;
     1061                    else
     1062                      {
     1063                        bfd_put_32 (output_bfd, relocation,
     1064                                    sgot->contents + off);
     1065                        h->got.offset |= 1;
     1066                      }
     1067                  }
     1068              }
     1069            else
     1070              {
     1071                BFD_ASSERT (local_got_offsets != NULL
     1072                            && local_got_offsets[r_symndx] != (bfd_vma) -1);
     1073
     1074                off = local_got_offsets[r_symndx];
     1075
     1076                /* The offset must always be a multiple of 4.  We use
     1077                   the least significant bit to record whether we have
     1078                   already generated the necessary reloc.  */
     1079                if ((off & 1) != 0)
     1080                  off &= ~1;
     1081                else
     1082                  {
     1083                    bfd_put_32 (output_bfd, relocation, sgot->contents + off);
     1084
     1085                    if (info->shared)
     1086                      {
     1087                        asection *s;
     1088                        Elf_Internal_Rela outrel;
     1089                        bfd_byte *loc;
     1090
     1091                        s = bfd_get_section_by_name (dynobj, ".rela.got");
     1092                        BFD_ASSERT (s != NULL);
     1093
     1094                        outrel.r_offset = (sgot->output_section->vma
     1095                                           + sgot->output_offset
     1096                                           + off);
     1097                        outrel.r_info = ELF32_R_INFO (0, R_CRIS_RELATIVE);
     1098                        outrel.r_addend = relocation;
     1099                        loc = s->contents;
     1100                        loc += s->reloc_count++ * sizeof (Elf32_External_Rela);
     1101                        bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
     1102                      }
     1103
     1104                    local_got_offsets[r_symndx] |= 1;
     1105                  }
     1106              }
     1107
     1108            relocation = sgot->output_offset + off;
     1109            if (rel->r_addend != 0)
     1110              {
     1111                /* We can't do anything for a relocation which is against
     1112                   a symbol *plus offset*.  GOT holds relocations for
     1113                   symbols.  Make this an error; the compiler isn't
     1114                   allowed to pass us these kinds of things.  */
     1115                if (h == NULL)
     1116                  (*_bfd_error_handler)
     1117                    (_("%s: relocation %s with non-zero addend %d against local symbol from %s section"),
     1118                     bfd_archive_filename (input_bfd),
     1119                     cris_elf_howto_table[r_type].name,
     1120                     rel->r_addend,
     1121                     bfd_get_section_name (input_bfd, input_section));
     1122                else
     1123                  (*_bfd_error_handler)
     1124                    (_("%s: relocation %s with non-zero addend %d against symbol `%s' from %s section"),
     1125                     bfd_archive_filename (input_bfd),
     1126                     cris_elf_howto_table[r_type].name,
     1127                     rel->r_addend,
     1128                     symname[0] != '\0' ? symname : _("[whose name is lost]"),
     1129                     bfd_get_section_name (input_bfd, input_section));
     1130
     1131                bfd_set_error (bfd_error_bad_value);
     1132                return FALSE;
     1133              }
     1134          }
     1135          break;
     1136
     1137        case R_CRIS_32_GOTREL:
     1138          /* This relocation must only be performed against local symbols.  */
     1139          if (h != NULL && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
     1140            {
     1141              (*_bfd_error_handler)
     1142                (_("%s: relocation %s is not allowed for global symbol: `%s' from %s section"),
     1143                 bfd_archive_filename (input_bfd),
     1144                 cris_elf_howto_table[r_type].name,
     1145                 symname,
     1146                 bfd_get_section_name (input_bfd, input_section));
     1147              bfd_set_error (bfd_error_bad_value);
     1148              return FALSE;
     1149            }
     1150
     1151          /* This can happen if we get a link error with the input ELF
     1152             variant mismatching the output variant.  Emit an error so
     1153             it's noticed if it happens elsewhere.  */
     1154          if (sgot == NULL)
     1155            {
     1156              (*_bfd_error_handler)
     1157                (_("%s: relocation %s in section %s with no GOT created"),
     1158                 bfd_archive_filename (input_bfd),
     1159                 cris_elf_howto_table[r_type].name,
     1160                 bfd_get_section_name (input_bfd, input_section));
     1161              bfd_set_error (bfd_error_bad_value);
     1162              return FALSE;
     1163            }
     1164
     1165          /* This relocation is like a PC-relative one, except the
     1166             reference point is the location of GOT.  Note that
     1167             sgot->output_offset is not involved in this calculation.  We
     1168             always want the start of entire .got section, not the
     1169             position after the reserved header.  */
     1170          relocation -= sgot->output_section->vma;
     1171          break;
     1172
     1173        case R_CRIS_32_PLT_PCREL:
     1174          /* Relocation is to the entry for this symbol in the
     1175             procedure linkage table.  */
     1176
     1177          /* Resolve a PLT_PCREL reloc against a local symbol directly,
     1178             without using the procedure linkage table.  */
     1179          if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
     1180            break;
     1181
     1182          if (h->plt.offset == (bfd_vma) -1
     1183              || splt == NULL)
     1184            {
     1185              /* We didn't make a PLT entry for this symbol.  This
     1186                 happens when statically linking PIC code, or when
     1187                 using -Bsymbolic.  */
     1188              break;
     1189            }
     1190
     1191          relocation = (splt->output_section->vma
     1192                        + splt->output_offset
     1193                        + h->plt.offset);
     1194          break;
     1195
     1196        case R_CRIS_32_PLT_GOTREL:
     1197          /* Like R_CRIS_32_PLT_PCREL, but the reference point is the
     1198             start of the .got section.  See also comment at
     1199             R_CRIS_32_GOT.  */
     1200          relocation -= sgot->output_section->vma;
     1201
     1202          /* Resolve a PLT_GOTREL reloc against a local symbol directly,
     1203             without using the procedure linkage table.  */
     1204          if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
     1205            break;
     1206
     1207          if (h->plt.offset == (bfd_vma) -1
     1208              || splt == NULL)
     1209            {
     1210              /* We didn't make a PLT entry for this symbol.  This
     1211                 happens when statically linking PIC code, or when
     1212                 using -Bsymbolic.  */
     1213              break;
     1214            }
     1215
     1216          relocation = (splt->output_section->vma
     1217                        + splt->output_offset
     1218                        + h->plt.offset
     1219                        - sgot->output_section->vma);
     1220          break;
     1221
     1222        case R_CRIS_8_PCREL:
     1223        case R_CRIS_16_PCREL:
     1224        case R_CRIS_32_PCREL:
     1225          /* If the symbol was local, we need no shlib-specific handling.  */
     1226          if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
     1227            break;
     1228
     1229          /* Fall through.  */
     1230        case R_CRIS_8:
     1231        case R_CRIS_16:
     1232        case R_CRIS_32:
     1233          if (info->shared
     1234              && r_symndx != 0
     1235              && (input_section->flags & SEC_ALLOC) != 0
     1236              && ((r_type != R_CRIS_8_PCREL
     1237                   && r_type != R_CRIS_16_PCREL
     1238                   && r_type != R_CRIS_32_PCREL)
     1239                  || (!info->symbolic
     1240                      || (h->elf_link_hash_flags
     1241                          & ELF_LINK_HASH_DEF_REGULAR) == 0)))
     1242            {
     1243              Elf_Internal_Rela outrel;
     1244              bfd_byte *loc;
     1245              bfd_boolean skip, relocate;
     1246
     1247              /* When generating a shared object, these relocations
     1248                 are copied into the output file to be resolved at run
     1249                 time.  */
     1250
     1251              if (sreloc == NULL)
     1252                {
     1253                  const char *name;
     1254
     1255                  name = (bfd_elf_string_from_elf_section
     1256                          (input_bfd,
     1257                           elf_elfheader (input_bfd)->e_shstrndx,
     1258                           elf_section_data (input_section)->rel_hdr.sh_name));
     1259                  if (name == NULL)
     1260                    return FALSE;
     1261
     1262                  BFD_ASSERT (strncmp (name, ".rela", 5) == 0
     1263                              && strcmp (bfd_get_section_name (input_bfd,
     1264                                                               input_section),
     1265                                         name + 5) == 0);
     1266
     1267                  sreloc = bfd_get_section_by_name (dynobj, name);
     1268
     1269                  /* That section should have been created in
     1270                     cris_elf_check_relocs, but that function will not be
     1271                     called for objects which fail in
     1272                     cris_elf_merge_private_bfd_data.  */
     1273                  if (sreloc == NULL)
     1274                    {
     1275                      (*_bfd_error_handler)
     1276                        (_("%s: Internal inconsistency; no relocation section %s"),
     1277                         bfd_archive_filename (input_bfd),
     1278                         name);
     1279
     1280                      bfd_set_error (bfd_error_bad_value);
     1281                      return FALSE;
     1282                    }
     1283                }
     1284
     1285              skip = FALSE;
     1286              relocate = FALSE;
     1287
     1288              outrel.r_offset =
     1289                _bfd_elf_section_offset (output_bfd, info, input_section,
     1290                                         rel->r_offset);
     1291              if (outrel.r_offset == (bfd_vma) -1)
     1292                skip = TRUE;
     1293              else if (outrel.r_offset == (bfd_vma) -2)
     1294                skip = TRUE, relocate = TRUE;
     1295              outrel.r_offset += (input_section->output_section->vma
     1296                                  + input_section->output_offset);
     1297
     1298              if (skip)
     1299                memset (&outrel, 0, sizeof outrel);
     1300              /* h->dynindx may be -1 if the symbol was marked to
     1301                 become local.  */
     1302              else if (h != NULL
     1303                       && ((! info->symbolic && h->dynindx != -1)
     1304                           || (h->elf_link_hash_flags
     1305                               & ELF_LINK_HASH_DEF_REGULAR) == 0))
     1306                {
     1307                  BFD_ASSERT (h->dynindx != -1);
     1308                  outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
     1309                  outrel.r_addend = relocation + rel->r_addend;
     1310                }
     1311              else
     1312                {
     1313                  if (r_type == R_CRIS_32)
     1314                    {
     1315                      relocate = TRUE;
     1316                      outrel.r_info = ELF32_R_INFO (0, R_CRIS_RELATIVE);
     1317                      outrel.r_addend = relocation + rel->r_addend;
     1318                    }
     1319                  else
     1320                    {
     1321                      long indx;
     1322
     1323                      if (h == NULL)
     1324                        sec = local_sections[r_symndx];
     1325                      else
     1326                        {
     1327                          BFD_ASSERT (h->root.type == bfd_link_hash_defined
     1328                                      || (h->root.type
     1329                                          == bfd_link_hash_defweak));
     1330                          sec = h->root.u.def.section;
     1331                        }
     1332                      if (sec != NULL && bfd_is_abs_section (sec))
     1333                        indx = 0;
     1334                      else if (sec == NULL || sec->owner == NULL)
     1335                        {
     1336                          bfd_set_error (bfd_error_bad_value);
     1337                          return FALSE;
     1338                        }
     1339                      else
     1340                        {
     1341                          asection *osec;
     1342
     1343                          osec = sec->output_section;
     1344                          indx = elf_section_data (osec)->dynindx;
     1345                          BFD_ASSERT (indx > 0);
     1346                        }
     1347
     1348                      outrel.r_info = ELF32_R_INFO (indx, r_type);
     1349                      outrel.r_addend = relocation + rel->r_addend;
     1350                    }
     1351                }
     1352
     1353              loc = sreloc->contents;
     1354              loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
     1355              bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
     1356
     1357              /* This reloc will be computed at runtime, so there's no
     1358                 need to do anything now, except for R_CRIS_32 relocations
     1359                 that have been turned into R_CRIS_RELATIVE.  */
     1360              if (!relocate)
     1361                continue;
     1362            }
     1363
     1364          break;
    4101365        }
    4111366
     
    4211376            case bfd_reloc_overflow:
    4221377              r = info->callbacks->reloc_overflow
    423                 (info, name, howto->name, (bfd_vma) 0,
     1378                (info, symname, howto->name, (bfd_vma) 0,
    4241379                 input_bfd, input_section, rel->r_offset);
    4251380              break;
     
    4271382            case bfd_reloc_undefined:
    4281383              r = info->callbacks->undefined_symbol
    429                 (info, name, input_bfd, input_section, rel->r_offset,
    430                  true);
     1384                (info, symname, input_bfd, input_section, rel->r_offset,
     1385                 TRUE);
    4311386              break;
    4321387
     
    4501405          if (msg)
    4511406            r = info->callbacks->warning
    452               (info, msg, name, input_bfd, input_section, rel->r_offset);
     1407              (info, msg, symname, input_bfd, input_section, rel->r_offset);
    4531408
    4541409          if (! r)
    455             return false;
     1410            return FALSE;
    4561411        }
    4571412    }
    4581413
    459   return true;
     1414  return TRUE;
     1415}
     1416
     1417
     1418/* Finish up dynamic symbol handling.  We set the contents of various
     1419   dynamic sections here.  */
     1420
     1421static bfd_boolean
     1422elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
     1423     bfd *output_bfd;
     1424     struct bfd_link_info *info;
     1425     struct elf_link_hash_entry *h;
     1426     Elf_Internal_Sym *sym;
     1427{
     1428  bfd *dynobj;
     1429  int plt_off1 = 2, plt_off2 = 10, plt_off3 = 16;
     1430
     1431  dynobj = elf_hash_table (info)->dynobj;
     1432
     1433  if (h->plt.offset != (bfd_vma) -1)
     1434    {
     1435      asection *splt;
     1436      asection *sgotplt;
     1437      asection *sgot;
     1438      asection *srela;
     1439      bfd_vma got_base;
     1440
     1441      bfd_vma gotplt_offset
     1442        = ((struct elf_cris_link_hash_entry *) h)->gotplt_offset;
     1443      Elf_Internal_Rela rela;
     1444      bfd_byte *loc;
     1445      bfd_boolean has_gotplt = gotplt_offset != 0;
     1446
     1447      /* Get the index in the procedure linkage table which
     1448         corresponds to this symbol.  This is the index of this symbol
     1449         in all the symbols for which we are making plt entries.  The
     1450         first entry in the procedure linkage table is reserved.  */
     1451      /* We have to count backwards here, and the result is only valid as
     1452         an index into .got.plt and its relocations.  FIXME: Constants...  */
     1453      bfd_vma gotplt_index = gotplt_offset/4 - 3;
     1454
     1455      /* Get the offset into the .got table of the entry that corresponds
     1456         to this function.  Note that we embed knowledge that "incoming"
     1457         .got goes after .got.plt in the output without padding (pointer
     1458         aligned).  However, that knowledge is present in several other
     1459         places too, here and in elflink.h at least.  */
     1460      bfd_vma got_offset
     1461        = (has_gotplt
     1462           ? gotplt_offset
     1463           : h->got.offset + elf_cris_hash_table(info)->next_gotplt_entry);
     1464
     1465      /* This symbol has an entry in the procedure linkage table.  Set it
     1466         up.  */
     1467
     1468      BFD_ASSERT (h->dynindx != -1);
     1469
     1470      splt = bfd_get_section_by_name (dynobj, ".plt");
     1471      sgot = bfd_get_section_by_name (dynobj, ".got");
     1472      sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
     1473      srela = bfd_get_section_by_name (dynobj, ".rela.plt");
     1474      BFD_ASSERT (splt != NULL && sgotplt != NULL
     1475                  && (! has_gotplt || srela != NULL));
     1476
     1477      got_base = sgotplt->output_section->vma + sgotplt->output_offset;
     1478
     1479      /* Fill in the entry in the procedure linkage table.  */
     1480      if (! info->shared)
     1481        {
     1482          memcpy (splt->contents + h->plt.offset, elf_cris_plt_entry,
     1483                  PLT_ENTRY_SIZE);
     1484
     1485          /* We need to enter the absolute address of the GOT entry here.  */
     1486          bfd_put_32 (output_bfd, got_base + got_offset,
     1487                      splt->contents + h->plt.offset + plt_off1);
     1488        }
     1489      else
     1490        {
     1491          memcpy (splt->contents + h->plt.offset, elf_cris_pic_plt_entry,
     1492                  PLT_ENTRY_SIZE);
     1493          bfd_put_32 (output_bfd, got_offset,
     1494                      splt->contents + h->plt.offset + plt_off1);
     1495        }
     1496
     1497      /* Fill in the plt entry and make a relocation, if this is a "real"
     1498         PLT entry.  */
     1499      if (has_gotplt)
     1500        {
     1501          /* Fill in the offset into the reloc table.  */
     1502          bfd_put_32 (output_bfd,
     1503                      gotplt_index * sizeof (Elf32_External_Rela),
     1504                      splt->contents + h->plt.offset + plt_off2);
     1505
     1506          /* Fill in the offset to the first PLT entry, where to "jump".  */
     1507          bfd_put_32 (output_bfd, - (h->plt.offset + plt_off3 + 4),
     1508                      splt->contents + h->plt.offset + plt_off3);
     1509
     1510          /* Fill in the entry in the global offset table with the address of
     1511             the relocating stub.  */
     1512          bfd_put_32 (output_bfd,
     1513                      (splt->output_section->vma
     1514                       + splt->output_offset
     1515                       + h->plt.offset
     1516                       + 8),
     1517                      sgotplt->contents + got_offset);
     1518
     1519          /* Fill in the entry in the .rela.plt section.  */
     1520          rela.r_offset = (sgotplt->output_section->vma
     1521                           + sgotplt->output_offset
     1522                           + got_offset);
     1523          rela.r_info = ELF32_R_INFO (h->dynindx, R_CRIS_JUMP_SLOT);
     1524          rela.r_addend = 0;
     1525          loc = srela->contents + gotplt_index * sizeof (Elf32_External_Rela);
     1526          bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
     1527        }
     1528
     1529      if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
     1530        {
     1531          /* Mark the symbol as undefined, rather than as defined in
     1532             the .plt section.  Leave the value alone.  */
     1533          sym->st_shndx = SHN_UNDEF;
     1534
     1535          /* FIXME: From elf32-sparc.c 2001-02-19 (1.18).  I still don't
     1536             know whether resetting the value is significant; if it really
     1537             is, rather than a quirk or bug in the sparc port, then I
     1538             believe we'd see this elsewhere.  */
     1539          /* If the symbol is weak, we do need to clear the value.
     1540             Otherwise, the PLT entry would provide a definition for
     1541             the symbol even if the symbol wasn't defined anywhere,
     1542             and so the symbol would never be NULL.  */
     1543          if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK)
     1544              == 0)
     1545            sym->st_value = 0;
     1546        }
     1547    }
     1548
     1549  /* We don't emit .got relocs for symbols that aren't in the
     1550     dynamic-symbols table for an ordinary program and are either defined
     1551     by the program or are undefined weak symbols.  */
     1552  if (h->got.offset != (bfd_vma) -1
     1553      && (info->shared
     1554          || (h->dynindx != -1
     1555              && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
     1556              && h->root.type != bfd_link_hash_undefweak)))
     1557    {
     1558      asection *sgot;
     1559      asection *srela;
     1560      Elf_Internal_Rela rela;
     1561      bfd_byte *loc;
     1562      bfd_byte *where;
     1563
     1564      /* This symbol has an entry in the global offset table.  Set it up.  */
     1565
     1566      sgot = bfd_get_section_by_name (dynobj, ".got");
     1567      srela = bfd_get_section_by_name (dynobj, ".rela.got");
     1568      BFD_ASSERT (sgot != NULL && srela != NULL);
     1569
     1570      rela.r_offset = (sgot->output_section->vma
     1571                       + sgot->output_offset
     1572                       + (h->got.offset &~ (bfd_vma) 1));
     1573
     1574      /* If this is a static link, or it is a -Bsymbolic link and the
     1575         symbol is defined locally or was forced to be local because
     1576         of a version file, we just want to emit a RELATIVE reloc.
     1577         The entry in the global offset table will already have been
     1578         initialized in the relocate_section function.  */
     1579      where = sgot->contents + (h->got.offset &~ (bfd_vma) 1);
     1580      if (! elf_hash_table (info)->dynamic_sections_created
     1581          || (info->shared
     1582              && (info->symbolic || h->dynindx == -1)
     1583              && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
     1584        {
     1585          rela.r_info = ELF32_R_INFO (0, R_CRIS_RELATIVE);
     1586          rela.r_addend = bfd_get_signed_32 (output_bfd, where);
     1587        }
     1588      else
     1589        {
     1590          bfd_put_32 (output_bfd, (bfd_vma) 0, where);
     1591          rela.r_info = ELF32_R_INFO (h->dynindx, R_CRIS_GLOB_DAT);
     1592          rela.r_addend = 0;
     1593        }
     1594
     1595      loc = srela->contents;
     1596      loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
     1597      bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
     1598    }
     1599
     1600  if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
     1601    {
     1602      asection *s;
     1603      Elf_Internal_Rela rela;
     1604      bfd_byte *loc;
     1605
     1606      /* This symbol needs a copy reloc.  Set it up.  */
     1607
     1608      BFD_ASSERT (h->dynindx != -1
     1609                  && (h->root.type == bfd_link_hash_defined
     1610                      || h->root.type == bfd_link_hash_defweak));
     1611
     1612      s = bfd_get_section_by_name (h->root.u.def.section->owner,
     1613                                   ".rela.bss");
     1614      BFD_ASSERT (s != NULL);
     1615
     1616      rela.r_offset = (h->root.u.def.value
     1617                       + h->root.u.def.section->output_section->vma
     1618                       + h->root.u.def.section->output_offset);
     1619      rela.r_info = ELF32_R_INFO (h->dynindx, R_CRIS_COPY);
     1620      rela.r_addend = 0;
     1621      loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
     1622      bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
     1623    }
     1624
     1625  /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
     1626  if (strcmp (h->root.root.string, "_DYNAMIC") == 0
     1627      || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
     1628    sym->st_shndx = SHN_ABS;
     1629
     1630  return TRUE;
     1631}
     1632
     1633
     1634/* Finish up the dynamic sections.  */
     1635
     1636static bfd_boolean
     1637elf_cris_finish_dynamic_sections (output_bfd, info)
     1638     bfd *output_bfd;
     1639     struct bfd_link_info *info;
     1640{
     1641  bfd *dynobj;
     1642  asection *sgot;
     1643  asection *sdyn;
     1644
     1645  dynobj = elf_hash_table (info)->dynobj;
     1646
     1647  sgot = bfd_get_section_by_name (dynobj, ".got.plt");
     1648  BFD_ASSERT (sgot != NULL);
     1649  sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
     1650
     1651  if (elf_hash_table (info)->dynamic_sections_created)
     1652    {
     1653      asection *splt;
     1654      Elf32_External_Dyn *dyncon, *dynconend;
     1655
     1656      splt = bfd_get_section_by_name (dynobj, ".plt");
     1657      BFD_ASSERT (splt != NULL && sdyn != NULL);
     1658
     1659      dyncon = (Elf32_External_Dyn *) sdyn->contents;
     1660      dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
     1661      for (; dyncon < dynconend; dyncon++)
     1662        {
     1663          Elf_Internal_Dyn dyn;
     1664          asection *s;
     1665
     1666          bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
     1667
     1668          switch (dyn.d_tag)
     1669            {
     1670            default:
     1671              break;
     1672
     1673            case DT_PLTGOT:
     1674              s = bfd_get_section_by_name (output_bfd, ".got");
     1675              BFD_ASSERT (s != NULL);
     1676              dyn.d_un.d_ptr = s->vma;
     1677              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
     1678              break;
     1679
     1680            case DT_JMPREL:
     1681              /* Yes, we *can* have a .plt and no .plt.rela, for instance
     1682                 if all symbols are found in the .got (not .got.plt).  */
     1683              s = bfd_get_section_by_name (output_bfd, ".rela.plt");
     1684              dyn.d_un.d_ptr = s != NULL ? s->vma : 0;
     1685              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
     1686              break;
     1687
     1688            case DT_PLTRELSZ:
     1689              s = bfd_get_section_by_name (output_bfd, ".rela.plt");
     1690              if (s == NULL)
     1691                dyn.d_un.d_val = 0;
     1692              else if (s->_cooked_size != 0)
     1693                dyn.d_un.d_val = s->_cooked_size;
     1694              else
     1695                dyn.d_un.d_val = s->_raw_size;
     1696              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
     1697              break;
     1698
     1699            case DT_RELASZ:
     1700              /* The procedure linkage table relocs (DT_JMPREL) should
     1701                 not be included in the overall relocs (DT_RELA).
     1702                 Therefore, we override the DT_RELASZ entry here to
     1703                 make it not include the JMPREL relocs.  Since the
     1704                 linker script arranges for .rela.plt to follow all
     1705                 other relocation sections, we don't have to worry
     1706                 about changing the DT_RELA entry.  */
     1707              s = bfd_get_section_by_name (output_bfd, ".rela.plt");
     1708              if (s != NULL)
     1709                {
     1710                  if (s->_cooked_size != 0)
     1711                    dyn.d_un.d_val -= s->_cooked_size;
     1712                  else
     1713                    dyn.d_un.d_val -= s->_raw_size;
     1714                }
     1715              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
     1716              break;
     1717            }
     1718        }
     1719
     1720      /* Fill in the first entry in the procedure linkage table.  */
     1721      if (splt->_raw_size > 0)
     1722        {
     1723          if (info->shared)
     1724            memcpy (splt->contents, elf_cris_pic_plt0_entry, PLT_ENTRY_SIZE);
     1725          else
     1726            {
     1727              memcpy (splt->contents, elf_cris_plt0_entry, PLT_ENTRY_SIZE);
     1728              bfd_put_32 (output_bfd,
     1729                          sgot->output_section->vma + sgot->output_offset + 4,
     1730                          splt->contents + 6);
     1731              bfd_put_32 (output_bfd,
     1732                          sgot->output_section->vma + sgot->output_offset + 8,
     1733                          splt->contents + 14);
     1734
     1735              elf_section_data (splt->output_section)->this_hdr.sh_entsize
     1736               = PLT_ENTRY_SIZE;
     1737            }
     1738        }
     1739    }
     1740
     1741  /* Fill in the first three entries in the global offset table.  */
     1742  if (sgot->_raw_size > 0)
     1743    {
     1744      if (sdyn == NULL)
     1745        bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
     1746      else
     1747        bfd_put_32 (output_bfd,
     1748                    sdyn->output_section->vma + sdyn->output_offset,
     1749                    sgot->contents);
     1750      bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
     1751      bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
     1752    }
     1753
     1754  elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
     1755
     1756  return TRUE;
    4601757}
    4611758
     
    4651762
    4661763static asection *
    467 cris_elf_gc_mark_hook (abfd, info, rel, h, sym)
    468      bfd *                        abfd;
    469      struct bfd_link_info *       info ATTRIBUTE_UNUSED;
    470      Elf_Internal_Rela *          rel;
    471      struct elf_link_hash_entry * h;
    472      Elf_Internal_Sym *           sym;
     1764cris_elf_gc_mark_hook (sec, info, rel, h, sym)
     1765     asection *sec;
     1766     struct bfd_link_info *info ATTRIBUTE_UNUSED;
     1767     Elf_Internal_Rela *rel;
     1768     struct elf_link_hash_entry *h;
     1769     Elf_Internal_Sym *sym;
    4731770{
    4741771  if (h != NULL)
     
    4961793    }
    4971794  else
     1795    return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
     1796
     1797  return NULL;
     1798}
     1799
     1800/* Update the got entry reference counts for the section being removed.  */
     1801
     1802static bfd_boolean
     1803cris_elf_gc_sweep_hook (abfd, info, sec, relocs)
     1804     bfd *abfd ATTRIBUTE_UNUSED;
     1805     struct bfd_link_info *info ATTRIBUTE_UNUSED;
     1806     asection *sec ATTRIBUTE_UNUSED;
     1807     const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
     1808{
     1809  Elf_Internal_Shdr *symtab_hdr;
     1810  struct elf_link_hash_entry **sym_hashes;
     1811  bfd_signed_vma *local_got_refcounts;
     1812  const Elf_Internal_Rela *rel, *relend;
     1813  unsigned long r_symndx;
     1814  struct elf_link_hash_entry *h;
     1815  bfd *dynobj;
     1816  asection *sgot;
     1817  asection *srelgot;
     1818
     1819  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
     1820  sym_hashes = elf_sym_hashes (abfd);
     1821  local_got_refcounts = elf_local_got_refcounts (abfd);
     1822
     1823  dynobj = elf_hash_table (info)->dynobj;
     1824  if (dynobj == NULL)
     1825    return TRUE;
     1826
     1827  sgot = bfd_get_section_by_name (dynobj, ".got");
     1828  srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
     1829
     1830  relend = relocs + sec->reloc_count;
     1831  for (rel = relocs; rel < relend; rel++)
    4981832    {
    499       if (!(elf_bad_symtab (abfd)
    500             && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
    501           && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
    502                 && sym->st_shndx != SHN_COMMON))
     1833      switch (ELF32_R_TYPE (rel->r_info))
    5031834        {
    504           return bfd_section_from_elf_index (abfd, sym->st_shndx);
     1835        case R_CRIS_16_GOT:
     1836        case R_CRIS_32_GOT:
     1837          r_symndx = ELF32_R_SYM (rel->r_info);
     1838          if (r_symndx >= symtab_hdr->sh_info)
     1839            {
     1840              h = sym_hashes[r_symndx - symtab_hdr->sh_info];
     1841              if (h->got.refcount > 0)
     1842                {
     1843                  --h->got.refcount;
     1844                  if (h->got.refcount == 0)
     1845                    {
     1846                      /* We don't need the .got entry any more.  */
     1847                      sgot->_raw_size -= 4;
     1848                      srelgot->_raw_size -= sizeof (Elf32_External_Rela);
     1849                    }
     1850                }
     1851              break;
     1852            }
     1853
     1854        local_got_reloc:
     1855          if (local_got_refcounts != NULL)
     1856            {
     1857              if (local_got_refcounts[r_symndx] > 0)
     1858                {
     1859                  --local_got_refcounts[r_symndx];
     1860                  if (local_got_refcounts[r_symndx] == 0)
     1861                    {
     1862                      /* We don't need the .got entry any more.  */
     1863                      sgot->_raw_size -= 4;
     1864                      if (info->shared)
     1865                        srelgot->_raw_size -= sizeof (Elf32_External_Rela);
     1866                    }
     1867                }
     1868            }
     1869          break;
     1870
     1871        case R_CRIS_16_GOTPLT:
     1872        case R_CRIS_32_GOTPLT:
     1873          /* For local symbols, treat these like GOT relocs.  */
     1874          r_symndx = ELF32_R_SYM (rel->r_info);
     1875          if (r_symndx < symtab_hdr->sh_info)
     1876            goto local_got_reloc;
     1877
     1878        case R_CRIS_32_PLT_GOTREL:
     1879          /* FIXME: We don't garbage-collect away the .got section.  */
     1880          if (local_got_refcounts != NULL)
     1881            local_got_refcounts[-1]--;
     1882          /* Fall through.  */
     1883
     1884        case R_CRIS_8_PCREL:
     1885        case R_CRIS_16_PCREL:
     1886        case R_CRIS_32_PCREL:
     1887        case R_CRIS_32_PLT_PCREL:
     1888          r_symndx = ELF32_R_SYM (rel->r_info);
     1889          if (r_symndx >= symtab_hdr->sh_info)
     1890            {
     1891              h = sym_hashes[r_symndx - symtab_hdr->sh_info];
     1892              if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
     1893                  && h->plt.refcount > 0)
     1894                --h->plt.refcount;
     1895            }
     1896          break;
     1897
     1898        default:
     1899          break;
    5051900        }
    5061901    }
    5071902
    508   return NULL;
     1903  return TRUE;
    5091904}
    5101905
    511 /* Update the got entry reference counts for the section being removed.  */
    512 
    513 static boolean
    514 cris_elf_gc_sweep_hook (abfd, info, sec, relocs)
    515      bfd *                     abfd ATTRIBUTE_UNUSED;
    516      struct bfd_link_info *    info ATTRIBUTE_UNUSED;
    517      asection *                sec ATTRIBUTE_UNUSED;
    518      const Elf_Internal_Rela * relocs ATTRIBUTE_UNUSED;
    519 {
    520   return true;
     1906/* Make sure we emit a GOT entry if the symbol was supposed to have a PLT
     1907   entry but we found we will not create any.  Called when we find we will
     1908   not have any PLT for this symbol, by for example
     1909   elf_cris_adjust_dynamic_symbol when we're doing a proper dynamic link,
     1910   or elf_cris_size_dynamic_sections if no dynamic sections will be
     1911   created (we're only linking static objects).  */
     1912
     1913static bfd_boolean
     1914elf_cris_adjust_gotplt_to_got (h, p)
     1915     struct elf_cris_link_hash_entry *h;
     1916     PTR p;
     1917{
     1918  struct bfd_link_info *info = (struct bfd_link_info *) p;
     1919  bfd *dynobj = elf_hash_table (info)->dynobj;
     1920
     1921  BFD_ASSERT (dynobj != NULL);
     1922
     1923  if (h->root.root.type == bfd_link_hash_warning)
     1924    h = (struct elf_cris_link_hash_entry *) h->root.root.u.i.link;
     1925
     1926  /* If nobody wanted a GOTPLT with this symbol, we're done.  */
     1927  if (h->gotplt_refcount <= 0)
     1928    return TRUE;
     1929
     1930  if (h->root.got.refcount > 0)
     1931    {
     1932      /* There's a GOT entry for this symbol.  Just adjust the refcount.
     1933         Probably not necessary at this stage, but keeping it accurate
     1934         helps avoiding surprises later.  */
     1935      h->root.got.refcount += h->gotplt_refcount;
     1936      h->gotplt_refcount = -1;
     1937    }
     1938  else
     1939    {
     1940      /* No GOT entry for this symbol.  We need to create one.  */
     1941      asection *sgot = bfd_get_section_by_name (dynobj, ".got");
     1942      asection *srelgot
     1943        = bfd_get_section_by_name (dynobj, ".rela.got");
     1944
     1945      /* Put an accurate refcount there.  */
     1946      h->root.got.refcount = h->gotplt_refcount;
     1947
     1948      h->gotplt_refcount = -1;
     1949
     1950      /* We always have a .got and a .rela.got section if there were
     1951         GOTPLT relocs in input.  */
     1952      BFD_ASSERT (sgot != NULL && srelgot != NULL);
     1953
     1954      /* Allocate space in the .got section.  */
     1955      sgot->_raw_size += 4;
     1956
     1957      /* Allocate relocation space.  */
     1958      srelgot->_raw_size += sizeof (Elf32_External_Rela);
     1959    }
     1960
     1961  return TRUE;
    5211962}
    5221963
    523 /* Look through the relocs for a section during the first phase.
    524    Since we don't do .gots or .plts, we just need to consider the
    525    virtual table relocs for gc.  */
    526 
    527 static boolean
     1964/* Try to fold PLT entries with GOT entries.  There are two cases when we
     1965   want to do this:
     1966
     1967   - When all PLT references are GOTPLT references, and there are GOT
     1968     references.  We don't have to generate a PLT at all.
     1969
     1970   - When there are both (ordinary) PLT references and GOT references.
     1971     We want to make the PLT reference use the ordinary GOT entry rather
     1972     than a run-time dynamically resolved GOTPLT entry (since the GOT
     1973     entry will have to be resolved at startup anyway).
     1974
     1975   Though the latter case is handled when room for the PLT is allocated,
     1976   not here.
     1977
     1978   Note that this function is called before symbols are forced local by
     1979   version scripts.  The differing cases are handled by
     1980   elf_cris_hide_symbol.  */
     1981
     1982static bfd_boolean
     1983elf_cris_try_fold_plt_to_got (h, p)
     1984     struct elf_cris_link_hash_entry *h;
     1985     PTR p;
     1986{
     1987  struct bfd_link_info *info = (struct bfd_link_info *) p;
     1988
     1989  /* If there are no GOT references for this symbol, we can't fold any
     1990     other reference so there's nothing to do.  Likewise if there are no
     1991     PLT references; GOTPLT references included.  */
     1992  if (h->root.got.refcount <= 0 || h->root.plt.refcount <= 0)
     1993    return TRUE;
     1994
     1995  /* GOTPLT relocs are supposed to be included into the PLT refcount.  */
     1996  BFD_ASSERT (h->gotplt_refcount <= h->root.plt.refcount);
     1997
     1998  if (h->gotplt_refcount == h->root.plt.refcount)
     1999    {
     2000      /* The only PLT references are GOTPLT references, and there are GOT
     2001         references.  Convert PLT to GOT references.  */
     2002      if (! elf_cris_adjust_gotplt_to_got (h, info))
     2003        return FALSE;
     2004
     2005      /* Clear the PLT references, so no PLT will be created.  */
     2006      h->root.plt.offset = (bfd_vma) -1;
     2007    }
     2008
     2009  return TRUE;
     2010}
     2011
     2012/* Our own version of hide_symbol, so that we can adjust a GOTPLT reloc
     2013   to use a GOT entry (and create one) rather than requiring a GOTPLT
     2014   entry.  */
     2015
     2016static void
     2017elf_cris_hide_symbol (info, h, force_local)
     2018     struct bfd_link_info *info;
     2019     struct elf_link_hash_entry *h;
     2020     bfd_boolean force_local;
     2021{
     2022  elf_cris_adjust_gotplt_to_got ((struct elf_cris_link_hash_entry *) h, info);
     2023
     2024  _bfd_elf_link_hash_hide_symbol (info, h, force_local);
     2025}
     2026
     2027/* Adjust a symbol defined by a dynamic object and referenced by a
     2028   regular object.  The current definition is in some section of the
     2029   dynamic object, but we're not including those sections.  We have to
     2030   change the definition to something the rest of the link can
     2031   understand.  */
     2032
     2033static bfd_boolean
     2034elf_cris_adjust_dynamic_symbol (info, h)
     2035     struct bfd_link_info *info;
     2036     struct elf_link_hash_entry *h;
     2037{
     2038  bfd *dynobj;
     2039  asection *s;
     2040  unsigned int power_of_two;
     2041
     2042  dynobj = elf_hash_table (info)->dynobj;
     2043
     2044  /* Make sure we know what is going on here.  */
     2045  BFD_ASSERT (dynobj != NULL
     2046              && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
     2047                  || h->weakdef != NULL
     2048                  || ((h->elf_link_hash_flags
     2049                       & ELF_LINK_HASH_DEF_DYNAMIC) != 0
     2050                      && (h->elf_link_hash_flags
     2051                          & ELF_LINK_HASH_REF_REGULAR) != 0
     2052                      && (h->elf_link_hash_flags
     2053                          & ELF_LINK_HASH_DEF_REGULAR) == 0)));
     2054
     2055  /* If this is a function, put it in the procedure linkage table.  We
     2056     will fill in the contents of the procedure linkage table later,
     2057     when we know the address of the .got section.  */
     2058  if (h->type == STT_FUNC
     2059      || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
     2060    {
     2061      /* If we link a program (not a DSO), we'll get rid of unnecessary
     2062         PLT entries; we point to the actual symbols -- even for pic
     2063         relocs, because a program built with -fpic should have the same
     2064         result as one built without -fpic, specifically considering weak
     2065         symbols.
     2066         FIXME: m68k and i386 differ here, for unclear reasons.  */
     2067      if (! info->shared
     2068          && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0)
     2069        {
     2070          /* This case can occur if we saw a PLT reloc in an input file,
     2071             but the symbol was not defined by a dynamic object.  In such
     2072             a case, we don't actually need to build a procedure linkage
     2073             table, and we can just do an absolute or PC reloc instead, or
     2074             change a .got.plt index to a .got index for GOTPLT relocs.  */
     2075          BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);
     2076          h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
     2077          h->plt.offset = (bfd_vma) -1;
     2078          return
     2079            elf_cris_adjust_gotplt_to_got ((struct
     2080                                            elf_cris_link_hash_entry *) h,
     2081                                           info);
     2082        }
     2083
     2084      /* If there are only GOT references and GOTPLT references to this
     2085         PLT entry, get rid of the PLT.  */
     2086      if (! elf_cris_try_fold_plt_to_got ((struct elf_cris_link_hash_entry *)
     2087                                          h, info))
     2088        return FALSE;
     2089
     2090      /* GC or folding may have rendered this entry unused.  */
     2091      if (h->plt.refcount <= 0)
     2092        {
     2093          h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
     2094          h->plt.offset = (bfd_vma) -1;
     2095          return TRUE;
     2096        }
     2097
     2098      /* Make sure this symbol is output as a dynamic symbol.  */
     2099      if (h->dynindx == -1)
     2100        {
     2101          if (! bfd_elf32_link_record_dynamic_symbol (info, h))
     2102            return FALSE;
     2103        }
     2104
     2105      s = bfd_get_section_by_name (dynobj, ".plt");
     2106      BFD_ASSERT (s != NULL);
     2107
     2108      /* If this is the first .plt entry, make room for the special
     2109         first entry.  */
     2110      if (s->_raw_size == 0)
     2111        s->_raw_size += PLT_ENTRY_SIZE;
     2112
     2113      /* If this symbol is not defined in a regular file, and we are
     2114         not generating a shared library, then set the symbol to this
     2115         location in the .plt.  */
     2116      if (!info->shared
     2117          && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
     2118        {
     2119          h->root.u.def.section = s;
     2120          h->root.u.def.value = s->_raw_size;
     2121        }
     2122
     2123      /* If there's already a GOT entry, use that, not a .got.plt.  A
     2124         GOT field still has a reference count when we get here; it's
     2125         not yet changed to an offset.  */
     2126      if (h->got.refcount > 0)
     2127        {
     2128          h->got.refcount += h->plt.refcount;
     2129
     2130          /* Mark the PLT offset to use the GOT entry by setting the low
     2131             bit in the plt offset; it is always a multiple of
     2132             pointer-size.  */
     2133          BFD_ASSERT ((s->_raw_size & 3) == 0);
     2134
     2135          /* Change the PLT refcount to an offset.  */
     2136          h->plt.offset = s->_raw_size;
     2137
     2138          /* By not setting gotplt_offset (i.e. it remains at 0), we signal
     2139             that the got entry should be used instead.  */
     2140          BFD_ASSERT (((struct elf_cris_link_hash_entry *)
     2141                       h)->gotplt_offset == 0);
     2142
     2143          /* Make room for this entry.  */
     2144          s->_raw_size += PLT_ENTRY_SIZE;
     2145
     2146          return TRUE;
     2147        }
     2148
     2149      /* No GOT reference for this symbol; prepare for an ordinary PLT.  */
     2150      h->plt.offset = s->_raw_size;
     2151
     2152      /* Make room for this entry.  */
     2153      s->_raw_size += PLT_ENTRY_SIZE;
     2154
     2155      /* We also need to make an entry in the .got.plt section, which
     2156         will be placed in the .got section by the linker script.  */
     2157      ((struct elf_cris_link_hash_entry *) h)->gotplt_offset
     2158        = elf_cris_hash_table (info)->next_gotplt_entry;
     2159      elf_cris_hash_table (info)->next_gotplt_entry += 4;
     2160
     2161      s = bfd_get_section_by_name (dynobj, ".got.plt");
     2162      BFD_ASSERT (s != NULL);
     2163      s->_raw_size += 4;
     2164
     2165      /* We also need to make an entry in the .rela.plt section.  */
     2166
     2167      s = bfd_get_section_by_name (dynobj, ".rela.plt");
     2168      BFD_ASSERT (s != NULL);
     2169      s->_raw_size += sizeof (Elf32_External_Rela);
     2170
     2171      return TRUE;
     2172    }
     2173
     2174  /* Reinitialize the plt offset now that it is not used as a reference
     2175     count any more.  */
     2176  h->plt.offset = (bfd_vma) -1;
     2177
     2178  /* If this is a weak symbol, and there is a real definition, the
     2179     processor independent code will have arranged for us to see the
     2180     real definition first, and we can just use the same value.  */
     2181  if (h->weakdef != NULL)
     2182    {
     2183      BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
     2184                  || h->weakdef->root.type == bfd_link_hash_defweak);
     2185      h->root.u.def.section = h->weakdef->root.u.def.section;
     2186      h->root.u.def.value = h->weakdef->root.u.def.value;
     2187      return TRUE;
     2188    }
     2189
     2190  /* This is a reference to a symbol defined by a dynamic object which
     2191     is not a function.  */
     2192
     2193  /* If we are creating a shared library, we must presume that the
     2194     only references to the symbol are via the global offset table.
     2195     For such cases we need not do anything here; the relocations will
     2196     be handled correctly by relocate_section.  */
     2197  if (info->shared)
     2198    return TRUE;
     2199
     2200  /* If there are no references to this symbol that do not use the
     2201     GOT, we don't need to generate a copy reloc.  */
     2202  if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
     2203    return TRUE;
     2204
     2205  /* We must allocate the symbol in our .dynbss section, which will
     2206     become part of the .bss section of the executable.  There will be
     2207     an entry for this symbol in the .dynsym section.  The dynamic
     2208     object will contain position independent code, so all references
     2209     from the dynamic object to this symbol will go through the global
     2210     offset table.  The dynamic linker will use the .dynsym entry to
     2211     determine the address it must put in the global offset table, so
     2212     both the dynamic object and the regular object will refer to the
     2213     same memory location for the variable.  */
     2214
     2215  s = bfd_get_section_by_name (dynobj, ".dynbss");
     2216  BFD_ASSERT (s != NULL);
     2217
     2218  /* We must generate a R_CRIS_COPY reloc to tell the dynamic linker to
     2219     copy the initial value out of the dynamic object and into the
     2220     runtime process image.  We need to remember the offset into the
     2221     .rela.bss section we are going to use.  */
     2222  if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
     2223    {
     2224      asection *srel;
     2225
     2226      srel = bfd_get_section_by_name (dynobj, ".rela.bss");
     2227      BFD_ASSERT (srel != NULL);
     2228      srel->_raw_size += sizeof (Elf32_External_Rela);
     2229      h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
     2230    }
     2231
     2232  /* Historic precedent: m68k and i386 allow max 8-byte alignment for the
     2233     thing to copy; so do we.  */
     2234
     2235  /* We need to figure out the alignment required for this symbol.  I
     2236     have no idea how ELF linkers handle this.  */
     2237  power_of_two = bfd_log2 (h->size);
     2238  if (power_of_two > 3)
     2239    power_of_two = 3;
     2240
     2241  /* Apply the required alignment.  */
     2242  s->_raw_size = BFD_ALIGN (s->_raw_size,
     2243                            (bfd_size_type) (1 << power_of_two));
     2244  if (power_of_two > bfd_get_section_alignment (dynobj, s))
     2245    {
     2246      if (!bfd_set_section_alignment (dynobj, s, power_of_two))
     2247        return FALSE;
     2248    }
     2249
     2250  /* Define the symbol as being at this point in the section.  */
     2251  h->root.u.def.section = s;
     2252  h->root.u.def.value = s->_raw_size;
     2253
     2254  /* Increment the section size to make room for the symbol.  */
     2255  s->_raw_size += h->size;
     2256
     2257  return TRUE;
     2258}
     2259
     2260/* Look through the relocs for a section during the first phase.  */
     2261
     2262static bfd_boolean
    5282263cris_elf_check_relocs (abfd, info, sec, relocs)
    5292264     bfd *abfd;
     
    5322267     const Elf_Internal_Rela *relocs;
    5332268{
     2269  bfd *dynobj;
    5342270  Elf_Internal_Shdr *symtab_hdr;
    5352271  struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
     2272  bfd_signed_vma *local_got_refcounts;
    5362273  const Elf_Internal_Rela *rel;
    5372274  const Elf_Internal_Rela *rel_end;
     2275  asection *sgot;
     2276  asection *srelgot;
     2277  asection *sreloc;
    5382278
    5392279  if (info->relocateable)
    540     return true;
    541 
     2280    return TRUE;
     2281
     2282  dynobj = elf_hash_table (info)->dynobj;
    5422283  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
    5432284  sym_hashes = elf_sym_hashes (abfd);
    5442285  sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym);
     2286  local_got_refcounts = elf_local_got_refcounts (abfd);
     2287
     2288  sgot = NULL;
     2289  srelgot = NULL;
     2290  sreloc = NULL;
     2291
    5452292  if (!elf_bad_symtab (abfd))
    5462293    sym_hashes_end -= symtab_hdr->sh_info;
     
    5512298      struct elf_link_hash_entry *h;
    5522299      unsigned long r_symndx;
     2300      enum elf_cris_reloc_type r_type;
    5532301
    5542302      r_symndx = ELF32_R_SYM (rel->r_info);
     
    5582306        h = sym_hashes[r_symndx - symtab_hdr->sh_info];
    5592307
    560       switch (ELF32_R_TYPE (rel->r_info))
     2308      r_type = ELF32_R_TYPE (rel->r_info);
     2309
     2310      /* Some relocs require linker-created sections; we need to hang them
     2311         on the first input bfd we found that contained dynamic relocs.  */
     2312      switch (r_type)
     2313        {
     2314        case R_CRIS_16_GOT:
     2315        case R_CRIS_32_GOT:
     2316        case R_CRIS_32_GOTREL:
     2317        case R_CRIS_32_PLT_GOTREL:
     2318        case R_CRIS_32_PLT_PCREL:
     2319        case R_CRIS_16_GOTPLT:
     2320        case R_CRIS_32_GOTPLT:
     2321          if (dynobj == NULL)
     2322            {
     2323              elf_hash_table (info)->dynobj = dynobj = abfd;
     2324
     2325              /* Create the .got section, so we can assume it's always
     2326                 present whenever there's a dynobj.  */
     2327              if (!_bfd_elf_create_got_section (dynobj, info))
     2328                return FALSE;
     2329            }
     2330          break;
     2331
     2332        default:
     2333          break;
     2334        }
     2335
     2336      /* Some relocs require a global offset table (but perhaps not a
     2337         specific GOT entry).  */
     2338      switch (r_type)
     2339        {
     2340          /* For R_CRIS_16_GOTPLT and R_CRIS_32_GOTPLT, we need a GOT
     2341             entry only for local symbols.  Unfortunately, we don't know
     2342             until later on if there's a version script that forces the
     2343             symbol local.  We must have the .rela.got section in place
     2344             before we know if the symbol looks global now, so we need
     2345             to treat the reloc just like for R_CRIS_16_GOT and
     2346             R_CRIS_32_GOT.  */
     2347        case R_CRIS_16_GOTPLT:
     2348        case R_CRIS_32_GOTPLT:
     2349        case R_CRIS_16_GOT:
     2350        case R_CRIS_32_GOT:
     2351          if (srelgot == NULL
     2352              && (h != NULL || info->shared))
     2353            {
     2354              srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
     2355              if (srelgot == NULL)
     2356                {
     2357                  srelgot = bfd_make_section (dynobj, ".rela.got");
     2358                  if (srelgot == NULL
     2359                      || !bfd_set_section_flags (dynobj, srelgot,
     2360                                                 (SEC_ALLOC
     2361                                                  | SEC_LOAD
     2362                                                  | SEC_HAS_CONTENTS
     2363                                                  | SEC_IN_MEMORY
     2364                                                  | SEC_LINKER_CREATED
     2365                                                  | SEC_READONLY))
     2366                      || !bfd_set_section_alignment (dynobj, srelgot, 2))
     2367                    return FALSE;
     2368                }
     2369            }
     2370          /* Fall through.  */
     2371
     2372        case R_CRIS_32_GOTREL:
     2373        case R_CRIS_32_PLT_GOTREL:
     2374          if (sgot == NULL)
     2375            sgot = bfd_get_section_by_name (dynobj, ".got");
     2376
     2377          if (local_got_refcounts == NULL)
     2378            {
     2379              bfd_size_type amt;
     2380
     2381              /* We use index local_got_refcounts[-1] to count all
     2382                 GOT-relative relocations that do not have explicit
     2383                 GOT entries.  */
     2384              amt = symtab_hdr->sh_info + 1;
     2385              amt *= sizeof (bfd_signed_vma);
     2386              local_got_refcounts = ((bfd_signed_vma *) bfd_zalloc (abfd, amt));
     2387              if (local_got_refcounts == NULL)
     2388                return FALSE;
     2389
     2390              local_got_refcounts++;
     2391              elf_local_got_refcounts (abfd) = local_got_refcounts;
     2392            }
     2393          break;
     2394
     2395        default:
     2396          break;
     2397        }
     2398
     2399      switch (r_type)
    5612400        {
     2401        case R_CRIS_16_GOTPLT:
     2402        case R_CRIS_32_GOTPLT:
     2403          /* Mark that we need a GOT entry if the PLT entry (and its GOT
     2404             entry) is eliminated.  We can only do this for a non-local
     2405             symbol.  */
     2406          if (h != NULL)
     2407            {
     2408              ((struct elf_cris_link_hash_entry *) h)->gotplt_refcount++;
     2409              goto handle_gotplt_reloc;
     2410            }
     2411          /* If h is NULL then this is a local symbol, and we must make a
     2412             GOT entry for it, so handle it like a GOT reloc.  */
     2413          /* Fall through.  */
     2414
     2415        case R_CRIS_16_GOT:
     2416        case R_CRIS_32_GOT:
     2417          /* This symbol requires a global offset table entry.  */
     2418          if (h != NULL)
     2419            {
     2420              if (h->got.refcount == 0)
     2421                {
     2422                  /* Make sure this symbol is output as a dynamic symbol.  */
     2423                  if (h->dynindx == -1)
     2424                    {
     2425                      if (!bfd_elf32_link_record_dynamic_symbol (info, h))
     2426                        return FALSE;
     2427                    }
     2428
     2429                  /* Allocate space in the .got section.  */
     2430                  sgot->_raw_size += 4;
     2431                  /* Allocate relocation space.  */
     2432                  srelgot->_raw_size += sizeof (Elf32_External_Rela);
     2433                }
     2434              h->got.refcount++;
     2435            }
     2436          else
     2437            {
     2438              /* This is a global offset table entry for a local symbol.  */
     2439              if (local_got_refcounts[r_symndx] == 0)
     2440                {
     2441                  sgot->_raw_size += 4;
     2442                  if (info->shared)
     2443                    {
     2444                      /* If we are generating a shared object, we need to
     2445                         output a R_CRIS_RELATIVE reloc so that the dynamic
     2446                         linker can adjust this GOT entry.  */
     2447                      srelgot->_raw_size += sizeof (Elf32_External_Rela);
     2448                    }
     2449                }
     2450              local_got_refcounts[r_symndx]++;
     2451            }
     2452          break;
     2453
     2454        case R_CRIS_32_GOTREL:
     2455          /* This reference requires a global offset table.
     2456             FIXME: The actual refcount isn't used currently; the .got
     2457             section can't be removed if there were any references in the
     2458             input.  */
     2459          local_got_refcounts[-1]++;
     2460          break;
     2461
     2462        handle_gotplt_reloc:
     2463
     2464        case R_CRIS_32_PLT_GOTREL:
     2465          /* This reference requires a global offset table.  */
     2466          local_got_refcounts[-1]++;
     2467          /* Fall through.  */
     2468
     2469        case R_CRIS_32_PLT_PCREL:
     2470          /* This symbol requires a procedure linkage table entry.  We
     2471             actually build the entry in adjust_dynamic_symbol,
     2472             because this might be a case of linking PIC code which is
     2473             never referenced by a dynamic object, in which case we
     2474             don't need to generate a procedure linkage table entry
     2475             after all.  */
     2476
     2477          /* If this is a local symbol, we resolve it directly without
     2478             creating a procedure linkage table entry.  */
     2479          if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
     2480            continue;
     2481
     2482          h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
     2483          h->plt.refcount++;
     2484          break;
     2485
     2486        case R_CRIS_8:
     2487        case R_CRIS_16:
     2488        case R_CRIS_32:
     2489          /* Let's help debug shared library creation.  Any of these
     2490             relocs can be used in shared libs, but pages containing them
     2491             cannot be shared.  Don't warn for sections we don't care
     2492             about, such as debug sections or non-constant sections.  We
     2493             can't help tables of (global) function pointers, for example,
     2494             though they must be emitted in a data section to avoid having
     2495             impure text sections.  */
     2496          if (info->shared
     2497              && (sec->flags & SEC_ALLOC) != 0
     2498              && (sec->flags & SEC_READONLY) != 0)
     2499            {
     2500              /* FIXME: How do we make this optionally a warning only?  */
     2501              (*_bfd_error_handler)
     2502                (_("%s, section %s:\n  relocation %s should not be used in a shared object; recompile with -fPIC"),
     2503                 bfd_archive_filename (abfd),
     2504                 sec->name,
     2505                 cris_elf_howto_table[r_type].name);
     2506            }
     2507          /* Fall through.  */
     2508
     2509        case R_CRIS_8_PCREL:
     2510        case R_CRIS_16_PCREL:
     2511        case R_CRIS_32_PCREL:
     2512          if (h != NULL)
     2513            {
     2514              h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
     2515
     2516              /* Make sure a plt entry is created for this symbol if it
     2517                 turns out to be a function defined by a dynamic object.  */
     2518              if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
     2519                h->plt.refcount++;
     2520            }
     2521
     2522          /* If we are creating a shared library and this is not a local
     2523             symbol, we need to copy the reloc into the shared library.
     2524             However when linking with -Bsymbolic and this is a global
     2525             symbol which is defined in an object we are including in the
     2526             link (i.e., DEF_REGULAR is set), then we can resolve the
     2527             reloc directly.  At this point we have not seen all the input
     2528             files, so it is possible that DEF_REGULAR is not set now but
     2529             will be set later (it is never cleared).  In case of a weak
     2530             definition, DEF_REGULAR may be cleared later by a strong
     2531             definition in a shared library.  We account for that
     2532             possibility below by storing information in the relocs_copied
     2533             field of the hash table entry.  A similar situation occurs
     2534             when creating shared libraries and symbol visibility changes
     2535             render the symbol local.  */
     2536
     2537          /* No need to do anything if we're not creating a shared object.  */
     2538          if (! info->shared)
     2539            break;
     2540
     2541          /* We don't need to handle relocs into sections not going into
     2542             the "real" output.  */
     2543          if ((sec->flags & SEC_ALLOC) == 0)
     2544            break;
     2545
     2546          /* We can only eliminate PC-relative relocs.  */
     2547          if (r_type == R_CRIS_8_PCREL
     2548              || r_type == R_CRIS_16_PCREL
     2549              || r_type == R_CRIS_32_PCREL)
     2550            {
     2551              /* If the symbol is local, then we can eliminate the reloc.  */
     2552              if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
     2553                break;
     2554
     2555              /* If this is with -Bsymbolic and the symbol isn't weak, and
     2556                 is defined by an ordinary object (the ones we include in
     2557                 this shared library) then we can also eliminate the
     2558                 reloc.  See comment above for more eliminable cases which
     2559                 we can't identify at this time.  */
     2560              if (info->symbolic
     2561                  && h->root.type != bfd_link_hash_defweak
     2562                  && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
     2563                break;
     2564            }
     2565
     2566          /* We create a reloc section in dynobj and make room for this
     2567             reloc.  */
     2568          if (sreloc == NULL)
     2569            {
     2570              const char *name;
     2571
     2572              name = (bfd_elf_string_from_elf_section
     2573                      (abfd,
     2574                       elf_elfheader (abfd)->e_shstrndx,
     2575                       elf_section_data (sec)->rel_hdr.sh_name));
     2576              if (name == NULL)
     2577                return FALSE;
     2578
     2579              BFD_ASSERT (strncmp (name, ".rela", 5) == 0
     2580                          && strcmp (bfd_get_section_name (abfd, sec),
     2581                                     name + 5) == 0);
     2582
     2583              sreloc = bfd_get_section_by_name (dynobj, name);
     2584              if (sreloc == NULL)
     2585                {
     2586                  sreloc = bfd_make_section (dynobj, name);
     2587                  if (sreloc == NULL
     2588                      || !bfd_set_section_flags (dynobj, sreloc,
     2589                                                 (SEC_ALLOC
     2590                                                  | SEC_LOAD
     2591                                                  | SEC_HAS_CONTENTS
     2592                                                  | SEC_IN_MEMORY
     2593                                                  | SEC_LINKER_CREATED
     2594                                                  | SEC_READONLY))
     2595                      || !bfd_set_section_alignment (dynobj, sreloc, 2))
     2596                    return FALSE;
     2597                }
     2598              if (sec->flags & SEC_READONLY)
     2599                info->flags |= DF_TEXTREL;
     2600            }
     2601
     2602          sreloc->_raw_size += sizeof (Elf32_External_Rela);
     2603
     2604          /* If we are linking with -Bsymbolic, we count the number of PC
     2605             relative relocations we have entered for this symbol, so that
     2606             we can discard them again if the symbol is later defined by a
     2607             regular object.  We know that h is really a pointer to an
     2608             elf_cris_link_hash_entry.  */
     2609          if ((r_type == R_CRIS_8_PCREL
     2610               || r_type == R_CRIS_16_PCREL
     2611               || r_type == R_CRIS_32_PCREL)
     2612              && info->symbolic)
     2613            {
     2614              struct elf_cris_link_hash_entry *eh;
     2615              struct elf_cris_pcrel_relocs_copied *p;
     2616
     2617              eh = (struct elf_cris_link_hash_entry *) h;
     2618
     2619              for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
     2620                if (p->section == sreloc)
     2621                  break;
     2622
     2623              if (p == NULL)
     2624                {
     2625                  p = ((struct elf_cris_pcrel_relocs_copied *)
     2626                       bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
     2627                  if (p == NULL)
     2628                    return FALSE;
     2629                  p->next = eh->pcrel_relocs_copied;
     2630                  eh->pcrel_relocs_copied = p;
     2631                  p->section = sreloc;
     2632                  p->count = 0;
     2633                }
     2634
     2635              ++p->count;
     2636            }
     2637          break;
     2638
    5622639        /* This relocation describes the C++ object vtable hierarchy.
    5632640           Reconstruct it for later use during GC.  */
    5642641        case R_CRIS_GNU_VTINHERIT:
    5652642          if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
    566             return false;
     2643            return FALSE;
    5672644          break;
    5682645
     
    5712648        case R_CRIS_GNU_VTENTRY:
    5722649          if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
    573             return false;
     2650            return FALSE;
    5742651          break;
     2652
     2653        default:
     2654          /* Other relocs do not appear here.  */
     2655          bfd_set_error (bfd_error_bad_value);
     2656          return FALSE;
    5752657        }
    5762658    }
    5772659
    578   return true;
     2660  return TRUE;
    5792661}
    5802662
    581 /* Reject a file depending on underscores on symbols.  */
    582 
    583 static boolean
     2663/* Set the sizes of the dynamic sections.  */
     2664
     2665static bfd_boolean
     2666elf_cris_size_dynamic_sections (output_bfd, info)
     2667     bfd *output_bfd ATTRIBUTE_UNUSED;
     2668     struct bfd_link_info *info;
     2669{
     2670  bfd *dynobj;
     2671  asection *s;
     2672  bfd_boolean plt;
     2673  bfd_boolean relocs;
     2674
     2675  dynobj = elf_hash_table (info)->dynobj;
     2676  BFD_ASSERT (dynobj != NULL);
     2677
     2678  if (elf_hash_table (info)->dynamic_sections_created)
     2679    {
     2680      /* Set the contents of the .interp section to the interpreter.  */
     2681      if (!info->shared)
     2682        {
     2683          s = bfd_get_section_by_name (dynobj, ".interp");
     2684          BFD_ASSERT (s != NULL);
     2685          s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
     2686          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
     2687        }
     2688    }
     2689  else
     2690    {
     2691      /* Adjust all expected GOTPLT uses to use a GOT entry instead.  */
     2692      elf_cris_link_hash_traverse (elf_cris_hash_table (info),
     2693                                   elf_cris_adjust_gotplt_to_got,
     2694                                   (PTR) info);
     2695
     2696      /* We may have created entries in the .rela.got section.
     2697         However, if we are not creating the dynamic sections, we will
     2698         not actually use these entries.  Reset the size of .rela.got,
     2699         which will cause it to get stripped from the output file
     2700         below.  */
     2701      s = bfd_get_section_by_name (dynobj, ".rela.got");
     2702      if (s != NULL)
     2703        s->_raw_size = 0;
     2704    }
     2705
     2706  /* If this is a -Bsymbolic shared link, then we need to discard all PC
     2707     relative relocs against symbols defined in a regular object.  We
     2708     allocated space for them in the check_relocs routine, but we will not
     2709     fill them in in the relocate_section routine.  We also discard space
     2710     for relocs that have become for local symbols due to symbol
     2711     visibility changes.  For programs, we discard space for relocs for
     2712     symbols not referenced by any dynamic object.  */
     2713  if (info->shared)
     2714    elf_cris_link_hash_traverse (elf_cris_hash_table (info),
     2715                                 elf_cris_discard_excess_dso_dynamics,
     2716                                 (PTR) info);
     2717  else
     2718    elf_cris_link_hash_traverse (elf_cris_hash_table (info),
     2719                                 elf_cris_discard_excess_program_dynamics,
     2720                                 (PTR) info);
     2721
     2722  /* The check_relocs and adjust_dynamic_symbol entry points have
     2723     determined the sizes of the various dynamic sections.  Allocate
     2724     memory for them.  */
     2725  plt = FALSE;
     2726  relocs = FALSE;
     2727  for (s = dynobj->sections; s != NULL; s = s->next)
     2728    {
     2729      const char *name;
     2730      bfd_boolean strip;
     2731
     2732      if ((s->flags & SEC_LINKER_CREATED) == 0)
     2733        continue;
     2734
     2735      /* It's OK to base decisions on the section name, because none
     2736         of the dynobj section names depend upon the input files.  */
     2737      name = bfd_get_section_name (dynobj, s);
     2738
     2739      strip = FALSE;
     2740
     2741      if (strcmp (name, ".plt") == 0)
     2742        {
     2743          if (s->_raw_size == 0)
     2744            {
     2745              /* Strip this section if we don't need it; see the
     2746                 comment below.  */
     2747              strip = TRUE;
     2748            }
     2749          else
     2750            {
     2751              /* Remember whether there is a PLT.  */
     2752              plt = TRUE;
     2753            }
     2754        }
     2755      else if (strncmp (name, ".rela", 5) == 0)
     2756        {
     2757          if (s->_raw_size == 0)
     2758            {
     2759              /* If we don't need this section, strip it from the
     2760                 output file.  This is mostly to handle .rela.bss and
     2761                 .rela.plt.  We must create both sections in
     2762                 create_dynamic_sections, because they must be created
     2763                 before the linker maps input sections to output
     2764                 sections.  The linker does that before
     2765                 adjust_dynamic_symbol is called, and it is that
     2766                 function which decides whether anything needs to go
     2767                 into these sections.  */
     2768              strip = TRUE;
     2769            }
     2770          else
     2771            {
     2772              /* Remember whether there are any reloc sections other
     2773                 than .rela.plt.  */
     2774              if (strcmp (name, ".rela.plt") != 0)
     2775                  relocs = TRUE;
     2776
     2777              /* We use the reloc_count field as a counter if we need
     2778                 to copy relocs into the output file.  */
     2779              s->reloc_count = 0;
     2780            }
     2781        }
     2782      else if (strncmp (name, ".got", 4) != 0)
     2783        {
     2784          /* It's not one of our sections, so don't allocate space.  */
     2785          continue;
     2786        }
     2787
     2788      if (strip)
     2789        {
     2790          _bfd_strip_section_from_output (info, s);
     2791          continue;
     2792        }
     2793
     2794      /* Allocate memory for the section contents. We use bfd_zalloc here
     2795         in case unused entries are not reclaimed before the section's
     2796         contents are written out.  This should not happen, but this way
     2797         if it does, we will not write out garbage.  For reloc sections,
     2798         this will make entries have the type R_CRIS_NONE.  */
     2799      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
     2800      if (s->contents == NULL && s->_raw_size != 0)
     2801        return FALSE;
     2802    }
     2803
     2804  if (elf_hash_table (info)->dynamic_sections_created)
     2805    {
     2806      /* Add some entries to the .dynamic section.  We fill in the
     2807         values later, in elf_cris_finish_dynamic_sections, but we
     2808         must add the entries now so that we get the correct size for
     2809         the .dynamic section.  The DT_DEBUG entry is filled in by the
     2810         dynamic linker and used by the debugger.  */
     2811#define add_dynamic_entry(TAG, VAL) \
     2812  bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
     2813
     2814      if (!info->shared)
     2815        {
     2816          if (!add_dynamic_entry (DT_DEBUG, 0))
     2817            return FALSE;
     2818        }
     2819
     2820      if (plt)
     2821        {
     2822          if (!add_dynamic_entry (DT_PLTGOT, 0)
     2823              || !add_dynamic_entry (DT_PLTRELSZ, 0)
     2824              || !add_dynamic_entry (DT_PLTREL, DT_RELA)
     2825              || !add_dynamic_entry (DT_JMPREL, 0))
     2826            return FALSE;
     2827        }
     2828
     2829      if (relocs)
     2830        {
     2831          if (!add_dynamic_entry (DT_RELA, 0)
     2832              || !add_dynamic_entry (DT_RELASZ, 0)
     2833              || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
     2834            return FALSE;
     2835        }
     2836
     2837      if ((info->flags & DF_TEXTREL) != 0)
     2838        {
     2839          if (!add_dynamic_entry (DT_TEXTREL, 0))
     2840            return FALSE;
     2841          info->flags |= DF_TEXTREL;
     2842        }
     2843    }
     2844#undef add_dynamic_entry
     2845
     2846  return TRUE;
     2847}
     2848
     2849/* This function is called via elf_cris_link_hash_traverse if we are
     2850   creating a shared object.  In the -Bsymbolic case, it discards the
     2851   space allocated to copy PC relative relocs against symbols which
     2852   are defined in regular objects.  For the normal non-symbolic case,
     2853   we also discard space for relocs that have become local due to
     2854   symbol visibility changes.  We allocated space for them in the
     2855   check_relocs routine, but we won't fill them in in the
     2856   relocate_section routine.  */
     2857
     2858static bfd_boolean
     2859elf_cris_discard_excess_dso_dynamics (h, inf)
     2860     struct elf_cris_link_hash_entry *h;
     2861     PTR inf;
     2862{
     2863  struct elf_cris_pcrel_relocs_copied *s;
     2864  struct bfd_link_info *info = (struct bfd_link_info *) inf;
     2865
     2866  if (h->root.root.type == bfd_link_hash_warning)
     2867    h = (struct elf_cris_link_hash_entry *) h->root.root.u.i.link;
     2868
     2869  /* If a symbol has been forced local or we have found a regular
     2870     definition for the symbolic link case, then we won't be needing
     2871     any relocs.  */
     2872  if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
     2873      && ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
     2874          || info->symbolic))
     2875    {
     2876      for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
     2877        s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela);
     2878    }
     2879
     2880  return TRUE;
     2881}
     2882
     2883/* This function is called via elf_cris_link_hash_traverse if we are *not*
     2884   creating a shared object.  We discard space for relocs for symbols put
     2885   in the .got, but which we found we do not have to resolve at run-time.  */
     2886
     2887static bfd_boolean
     2888elf_cris_discard_excess_program_dynamics (h, inf)
     2889     struct elf_cris_link_hash_entry *h;
     2890     PTR inf;
     2891{
     2892  struct bfd_link_info *info = (struct bfd_link_info *) inf;
     2893
     2894  if (h->root.root.type == bfd_link_hash_warning)
     2895    h = (struct elf_cris_link_hash_entry *) h->root.root.u.i.link;
     2896
     2897  /* If we're not creating a shared library and have a symbol which is
     2898     referred to by .got references, but the symbol is defined locally,
     2899     (or rather, not not defined by a DSO) then lose the reloc for the
     2900     .got (don't allocate room for it).  */
     2901  if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0)
     2902    {
     2903      if (h->root.got.refcount > 0
     2904          /* The size of this section is only valid and in sync with the
     2905             various reference counts if we do dynamic; don't decrement it
     2906             otherwise.  */
     2907          && elf_hash_table (info)->dynamic_sections_created)
     2908        {
     2909          bfd *dynobj = elf_hash_table (info)->dynobj;
     2910          asection *srelgot;
     2911
     2912          BFD_ASSERT (dynobj != NULL);
     2913
     2914          srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
     2915
     2916          BFD_ASSERT (srelgot != NULL);
     2917
     2918          srelgot->_raw_size -= sizeof (Elf32_External_Rela);
     2919        }
     2920
     2921      /* If the locally-defined symbol isn't used by a DSO, then we don't
     2922         have to export it as a dynamic symbol.  This was already done for
     2923         functions; doing this for all symbols would presumably not
     2924         introduce new problems.  Of course we don't do this if we're
     2925         exporting all dynamic symbols.  */
     2926      if (! info->export_dynamic
     2927          && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)
     2928        {
     2929          h->root.dynindx = -1;
     2930          _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
     2931                                  h->root.dynstr_index);
     2932        }
     2933    }
     2934
     2935  return TRUE;
     2936}
     2937
     2938/* Reject a file depending on presence and expectation of prefixed
     2939   underscores on symbols.  */
     2940
     2941static bfd_boolean
    5842942cris_elf_object_p (abfd)
    5852943     bfd *abfd;
     
    5962954cris_elf_final_write_processing (abfd, linker)
    5972955     bfd *abfd;
    598      boolean linker ATTRIBUTE_UNUSED;
     2956     bfd_boolean linker ATTRIBUTE_UNUSED;
    5992957{
    6002958  if (bfd_get_symbol_leading_char (abfd) == '_')
     
    6062964/* Display the flags field.  */
    6072965
    608 static boolean
     2966static bfd_boolean
    6092967cris_elf_print_private_bfd_data (abfd, ptr)
    6102968     bfd *abfd;
     
    6232981
    6242982  fputc ('\n', file);
    625   return true;
     2983  return TRUE;
    6262984}
    6272985
    6282986/* Don't mix files with and without a leading underscore.  */
    6292987
    630 static boolean
     2988static bfd_boolean
    6312989cris_elf_merge_private_bfd_data (ibfd, obfd)
    6322990     bfd *ibfd;
     
    6352993  flagword old_flags, new_flags;
    6362994
    637   if (_bfd_generic_verify_endian_match (ibfd, obfd) == false)
    638     return false;
     2995  if (! _bfd_generic_verify_endian_match (ibfd, obfd))
     2996    return FALSE;
    6392997
    6402998  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
    6412999      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
    642     return true;
     3000    return TRUE;
    6433001
    6443002  if (! elf_flags_init (obfd))
    6453003    {
    6463004      /* This happens when ld starts out with a 'blank' output file.  */
    647       elf_flags_init (obfd) = true;
     3005      elf_flags_init (obfd) = TRUE;
    6483006
    6493007      /* Set flags according to current bfd_target.  */
    650       cris_elf_final_write_processing (obfd, false);
     3008      cris_elf_final_write_processing (obfd, FALSE);
    6513009    }
    6523010
     
    6613019         ? _("%s: uses _-prefixed symbols, but writing file with non-prefixed symbols")
    6623020         : _("%s: uses non-prefixed symbols, but writing file with _-prefixed symbols"),
    663          bfd_get_filename (ibfd));
     3021         bfd_archive_filename (ibfd));
    6643022      bfd_set_error (bfd_error_bad_value);
    665       return false;
     3023      return FALSE;
    6663024    }
    6673025
    668   return true;
     3026  return TRUE;
     3027}
     3028
     3029
     3030static enum elf_reloc_type_class
     3031elf_cris_reloc_type_class (rela)
     3032     const Elf_Internal_Rela *rela;
     3033{
     3034  switch ((int) ELF32_R_TYPE (rela->r_info))
     3035    {
     3036    case R_CRIS_RELATIVE:
     3037      return reloc_class_relative;
     3038    case R_CRIS_JUMP_SLOT:
     3039      return reloc_class_plt;
     3040    case R_CRIS_COPY:
     3041      return reloc_class_copy;
     3042    default:
     3043      return reloc_class_normal;
     3044    }
    6693045}
    6703046
     
    6843060#define elf_backend_gc_sweep_hook               cris_elf_gc_sweep_hook
    6853061#define elf_backend_check_relocs                cris_elf_check_relocs
     3062#define elf_backend_grok_prstatus               cris_elf_grok_prstatus
     3063#define elf_backend_grok_psinfo                 cris_elf_grok_psinfo
    6863064
    6873065#define elf_backend_can_gc_sections             1
     3066#define elf_backend_can_refcount                1
    6883067
    6893068#define elf_backend_object_p                    cris_elf_object_p
     
    6973076#define bfd_elf32_bfd_reloc_type_lookup         cris_reloc_type_lookup
    6983077
     3078#define bfd_elf32_bfd_link_hash_table_create \
     3079        elf_cris_link_hash_table_create
     3080#define elf_backend_adjust_dynamic_symbol \
     3081        elf_cris_adjust_dynamic_symbol
     3082#define elf_backend_size_dynamic_sections \
     3083        elf_cris_size_dynamic_sections
     3084#define elf_backend_finish_dynamic_symbol \
     3085        elf_cris_finish_dynamic_symbol
     3086#define elf_backend_finish_dynamic_sections \
     3087        elf_cris_finish_dynamic_sections
     3088#define elf_backend_create_dynamic_sections \
     3089        _bfd_elf_create_dynamic_sections
     3090#define bfd_elf32_bfd_final_link \
     3091        _bfd_elf32_gc_common_final_link
     3092#define elf_backend_hide_symbol                 elf_cris_hide_symbol
     3093#define elf_backend_reloc_type_class            elf_cris_reloc_type_class
     3094
     3095#define elf_backend_want_got_plt        1
     3096#define elf_backend_plt_readonly        1
     3097#define elf_backend_want_plt_sym        0
     3098#define elf_backend_got_header_size     12
     3099#define elf_backend_plt_header_size     PLT_ENTRY_SIZE
     3100
    6993101/* Later, we my want to optimize RELA entries into REL entries for dynamic
    7003102   linking and libraries (if it's a win of any significance).  Until then,
     
    7023104#define elf_backend_may_use_rel_p 0
    7033105#define elf_backend_may_use_rela_p 1
     3106#define elf_backend_rela_normal         1
    7043107
    7053108#include "elf32-target.h"
Note: See TracChangeset for help on using the changeset viewer.