Back to index

cell-binutils  2.17cvs20070401
elf64-sparc.c
Go to the documentation of this file.
00001 /* SPARC-specific support for 64-bit ELF
00002    Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
00003    2003, 2004, 2005, 2007 Free Software Foundation, Inc.
00004 
00005    This file is part of BFD, the Binary File Descriptor library.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00020 
00021 #include "bfd.h"
00022 #include "sysdep.h"
00023 #include "libbfd.h"
00024 #include "elf-bfd.h"
00025 #include "elf/sparc.h"
00026 #include "opcode/sparc.h"
00027 #include "elfxx-sparc.h"
00028 
00029 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value.  */
00030 #define MINUS_ONE (~ (bfd_vma) 0)
00031 
00032 /* Due to the way how we handle R_SPARC_OLO10, each entry in a SHT_RELA
00033    section can represent up to two relocs, we must tell the user to allocate
00034    more space.  */
00035 
00036 static long
00037 elf64_sparc_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
00038 {
00039   return (sec->reloc_count * 2 + 1) * sizeof (arelent *);
00040 }
00041 
00042 static long
00043 elf64_sparc_get_dynamic_reloc_upper_bound (bfd *abfd)
00044 {
00045   return _bfd_elf_get_dynamic_reloc_upper_bound (abfd) * 2;
00046 }
00047 
00048 /* Read  relocations for ASECT from REL_HDR.  There are RELOC_COUNT of
00049    them.  We cannot use generic elf routines for this,  because R_SPARC_OLO10
00050    has secondary addend in ELF64_R_TYPE_DATA.  We handle it as two relocations
00051    for the same location,  R_SPARC_LO10 and R_SPARC_13.  */
00052 
00053 static bfd_boolean
00054 elf64_sparc_slurp_one_reloc_table (bfd *abfd, asection *asect,
00055                                Elf_Internal_Shdr *rel_hdr,
00056                                asymbol **symbols, bfd_boolean dynamic)
00057 {
00058   PTR allocated = NULL;
00059   bfd_byte *native_relocs;
00060   arelent *relent;
00061   unsigned int i;
00062   int entsize;
00063   bfd_size_type count;
00064   arelent *relents;
00065 
00066   allocated = (PTR) bfd_malloc (rel_hdr->sh_size);
00067   if (allocated == NULL)
00068     goto error_return;
00069 
00070   if (bfd_seek (abfd, rel_hdr->sh_offset, SEEK_SET) != 0
00071       || bfd_bread (allocated, rel_hdr->sh_size, abfd) != rel_hdr->sh_size)
00072     goto error_return;
00073 
00074   native_relocs = (bfd_byte *) allocated;
00075 
00076   relents = asect->relocation + canon_reloc_count (asect);
00077 
00078   entsize = rel_hdr->sh_entsize;
00079   BFD_ASSERT (entsize == sizeof (Elf64_External_Rela));
00080 
00081   count = rel_hdr->sh_size / entsize;
00082 
00083   for (i = 0, relent = relents; i < count;
00084        i++, relent++, native_relocs += entsize)
00085     {
00086       Elf_Internal_Rela rela;
00087       unsigned int r_type;
00088 
00089       bfd_elf64_swap_reloca_in (abfd, native_relocs, &rela);
00090 
00091       /* The address of an ELF reloc is section relative for an object
00092         file, and absolute for an executable file or shared library.
00093         The address of a normal BFD reloc is always section relative,
00094         and the address of a dynamic reloc is absolute..  */
00095       if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0 || dynamic)
00096        relent->address = rela.r_offset;
00097       else
00098        relent->address = rela.r_offset - asect->vma;
00099 
00100       if (ELF64_R_SYM (rela.r_info) == 0)
00101        relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
00102       else
00103        {
00104          asymbol **ps, *s;
00105 
00106          ps = symbols + ELF64_R_SYM (rela.r_info) - 1;
00107          s = *ps;
00108 
00109          /* Canonicalize ELF section symbols.  FIXME: Why?  */
00110          if ((s->flags & BSF_SECTION_SYM) == 0)
00111            relent->sym_ptr_ptr = ps;
00112          else
00113            relent->sym_ptr_ptr = s->section->symbol_ptr_ptr;
00114        }
00115 
00116       relent->addend = rela.r_addend;
00117 
00118       r_type = ELF64_R_TYPE_ID (rela.r_info);
00119       if (r_type == R_SPARC_OLO10)
00120        {
00121          relent->howto = _bfd_sparc_elf_info_to_howto_ptr (R_SPARC_LO10);
00122          relent[1].address = relent->address;
00123          relent++;
00124          relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
00125          relent->addend = ELF64_R_TYPE_DATA (rela.r_info);
00126          relent->howto = _bfd_sparc_elf_info_to_howto_ptr (R_SPARC_13);
00127        }
00128       else
00129        relent->howto = _bfd_sparc_elf_info_to_howto_ptr (r_type);
00130     }
00131 
00132   canon_reloc_count (asect) += relent - relents;
00133 
00134   if (allocated != NULL)
00135     free (allocated);
00136 
00137   return TRUE;
00138 
00139  error_return:
00140   if (allocated != NULL)
00141     free (allocated);
00142   return FALSE;
00143 }
00144 
00145 /* Read in and swap the external relocs.  */
00146 
00147 static bfd_boolean
00148 elf64_sparc_slurp_reloc_table (bfd *abfd, asection *asect,
00149                             asymbol **symbols, bfd_boolean dynamic)
00150 {
00151   struct bfd_elf_section_data * const d = elf_section_data (asect);
00152   Elf_Internal_Shdr *rel_hdr;
00153   Elf_Internal_Shdr *rel_hdr2;
00154   bfd_size_type amt;
00155 
00156   if (asect->relocation != NULL)
00157     return TRUE;
00158 
00159   if (! dynamic)
00160     {
00161       if ((asect->flags & SEC_RELOC) == 0
00162          || asect->reloc_count == 0)
00163        return TRUE;
00164 
00165       rel_hdr = &d->rel_hdr;
00166       rel_hdr2 = d->rel_hdr2;
00167 
00168       BFD_ASSERT (asect->rel_filepos == rel_hdr->sh_offset
00169                 || (rel_hdr2 && asect->rel_filepos == rel_hdr2->sh_offset));
00170     }
00171   else
00172     {
00173       /* Note that ASECT->RELOC_COUNT tends not to be accurate in this
00174         case because relocations against this section may use the
00175         dynamic symbol table, and in that case bfd_section_from_shdr
00176         in elf.c does not update the RELOC_COUNT.  */
00177       if (asect->size == 0)
00178        return TRUE;
00179 
00180       rel_hdr = &d->this_hdr;
00181       asect->reloc_count = NUM_SHDR_ENTRIES (rel_hdr);
00182       rel_hdr2 = NULL;
00183     }
00184 
00185   amt = asect->reloc_count;
00186   amt *= 2 * sizeof (arelent);
00187   asect->relocation = (arelent *) bfd_alloc (abfd, amt);
00188   if (asect->relocation == NULL)
00189     return FALSE;
00190 
00191   /* The elf64_sparc_slurp_one_reloc_table routine increments
00192      canon_reloc_count.  */
00193   canon_reloc_count (asect) = 0;
00194 
00195   if (!elf64_sparc_slurp_one_reloc_table (abfd, asect, rel_hdr, symbols,
00196                                      dynamic))
00197     return FALSE;
00198 
00199   if (rel_hdr2
00200       && !elf64_sparc_slurp_one_reloc_table (abfd, asect, rel_hdr2, symbols,
00201                                         dynamic))
00202     return FALSE;
00203 
00204   return TRUE;
00205 }
00206 
00207 /* Canonicalize the relocs.  */
00208 
00209 static long
00210 elf64_sparc_canonicalize_reloc (bfd *abfd, sec_ptr section,
00211                             arelent **relptr, asymbol **symbols)
00212 {
00213   arelent *tblptr;
00214   unsigned int i;
00215   const struct elf_backend_data *bed = get_elf_backend_data (abfd);
00216 
00217   if (! bed->s->slurp_reloc_table (abfd, section, symbols, FALSE))
00218     return -1;
00219 
00220   tblptr = section->relocation;
00221   for (i = 0; i < canon_reloc_count (section); i++)
00222     *relptr++ = tblptr++;
00223 
00224   *relptr = NULL;
00225 
00226   return canon_reloc_count (section);
00227 }
00228 
00229 
00230 /* Canonicalize the dynamic relocation entries.  Note that we return
00231    the dynamic relocations as a single block, although they are
00232    actually associated with particular sections; the interface, which
00233    was designed for SunOS style shared libraries, expects that there
00234    is only one set of dynamic relocs.  Any section that was actually
00235    installed in the BFD, and has type SHT_REL or SHT_RELA, and uses
00236    the dynamic symbol table, is considered to be a dynamic reloc
00237    section.  */
00238 
00239 static long
00240 elf64_sparc_canonicalize_dynamic_reloc (bfd *abfd, arelent **storage,
00241                                    asymbol **syms)
00242 {
00243   asection *s;
00244   long ret;
00245 
00246   if (elf_dynsymtab (abfd) == 0)
00247     {
00248       bfd_set_error (bfd_error_invalid_operation);
00249       return -1;
00250     }
00251 
00252   ret = 0;
00253   for (s = abfd->sections; s != NULL; s = s->next)
00254     {
00255       if (elf_section_data (s)->this_hdr.sh_link == elf_dynsymtab (abfd)
00256          && (elf_section_data (s)->this_hdr.sh_type == SHT_RELA))
00257        {
00258          arelent *p;
00259          long count, i;
00260 
00261          if (! elf64_sparc_slurp_reloc_table (abfd, s, syms, TRUE))
00262            return -1;
00263          count = canon_reloc_count (s);
00264          p = s->relocation;
00265          for (i = 0; i < count; i++)
00266            *storage++ = p++;
00267          ret += count;
00268        }
00269     }
00270 
00271   *storage = NULL;
00272 
00273   return ret;
00274 }
00275 
00276 /* Write out the relocs.  */
00277 
00278 static void
00279 elf64_sparc_write_relocs (bfd *abfd, asection *sec, PTR data)
00280 {
00281   bfd_boolean *failedp = (bfd_boolean *) data;
00282   Elf_Internal_Shdr *rela_hdr;
00283   bfd_vma addr_offset;
00284   Elf64_External_Rela *outbound_relocas, *src_rela;
00285   unsigned int idx, count;
00286   asymbol *last_sym = 0;
00287   int last_sym_idx = 0;
00288 
00289   /* If we have already failed, don't do anything.  */
00290   if (*failedp)
00291     return;
00292 
00293   if ((sec->flags & SEC_RELOC) == 0)
00294     return;
00295 
00296   /* The linker backend writes the relocs out itself, and sets the
00297      reloc_count field to zero to inhibit writing them here.  Also,
00298      sometimes the SEC_RELOC flag gets set even when there aren't any
00299      relocs.  */
00300   if (sec->reloc_count == 0)
00301     return;
00302 
00303   /* We can combine two relocs that refer to the same address
00304      into R_SPARC_OLO10 if first one is R_SPARC_LO10 and the
00305      latter is R_SPARC_13 with no associated symbol.  */
00306   count = 0;
00307   for (idx = 0; idx < sec->reloc_count; idx++)
00308     {
00309       bfd_vma addr;
00310 
00311       ++count;
00312 
00313       addr = sec->orelocation[idx]->address;
00314       if (sec->orelocation[idx]->howto->type == R_SPARC_LO10
00315          && idx < sec->reloc_count - 1)
00316        {
00317          arelent *r = sec->orelocation[idx + 1];
00318 
00319          if (r->howto->type == R_SPARC_13
00320              && r->address == addr
00321              && bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
00322              && (*r->sym_ptr_ptr)->value == 0)
00323            ++idx;
00324        }
00325     }
00326 
00327   rela_hdr = &elf_section_data (sec)->rel_hdr;
00328 
00329   rela_hdr->sh_size = rela_hdr->sh_entsize * count;
00330   rela_hdr->contents = (PTR) bfd_alloc (abfd, rela_hdr->sh_size);
00331   if (rela_hdr->contents == NULL)
00332     {
00333       *failedp = TRUE;
00334       return;
00335     }
00336 
00337   /* Figure out whether the relocations are RELA or REL relocations.  */
00338   if (rela_hdr->sh_type != SHT_RELA)
00339     abort ();
00340 
00341   /* The address of an ELF reloc is section relative for an object
00342      file, and absolute for an executable file or shared library.
00343      The address of a BFD reloc is always section relative.  */
00344   addr_offset = 0;
00345   if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
00346     addr_offset = sec->vma;
00347 
00348   /* orelocation has the data, reloc_count has the count...  */
00349   outbound_relocas = (Elf64_External_Rela *) rela_hdr->contents;
00350   src_rela = outbound_relocas;
00351 
00352   for (idx = 0; idx < sec->reloc_count; idx++)
00353     {
00354       Elf_Internal_Rela dst_rela;
00355       arelent *ptr;
00356       asymbol *sym;
00357       int n;
00358 
00359       ptr = sec->orelocation[idx];
00360       sym = *ptr->sym_ptr_ptr;
00361       if (sym == last_sym)
00362        n = last_sym_idx;
00363       else if (bfd_is_abs_section (sym->section) && sym->value == 0)
00364        n = STN_UNDEF;
00365       else
00366        {
00367          last_sym = sym;
00368          n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym);
00369          if (n < 0)
00370            {
00371              *failedp = TRUE;
00372              return;
00373            }
00374          last_sym_idx = n;
00375        }
00376 
00377       if ((*ptr->sym_ptr_ptr)->the_bfd != NULL
00378          && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
00379          && ! _bfd_elf_validate_reloc (abfd, ptr))
00380        {
00381          *failedp = TRUE;
00382          return;
00383        }
00384 
00385       if (ptr->howto->type == R_SPARC_LO10
00386          && idx < sec->reloc_count - 1)
00387        {
00388          arelent *r = sec->orelocation[idx + 1];
00389 
00390          if (r->howto->type == R_SPARC_13
00391              && r->address == ptr->address
00392              && bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
00393              && (*r->sym_ptr_ptr)->value == 0)
00394            {
00395              idx++;
00396              dst_rela.r_info
00397               = ELF64_R_INFO (n, ELF64_R_TYPE_INFO (r->addend,
00398                                                 R_SPARC_OLO10));
00399            }
00400          else
00401            dst_rela.r_info = ELF64_R_INFO (n, R_SPARC_LO10);
00402        }
00403       else
00404        dst_rela.r_info = ELF64_R_INFO (n, ptr->howto->type);
00405 
00406       dst_rela.r_offset = ptr->address + addr_offset;
00407       dst_rela.r_addend = ptr->addend;
00408 
00409       bfd_elf64_swap_reloca_out (abfd, &dst_rela, (bfd_byte *) src_rela);
00410       ++src_rela;
00411     }
00412 }
00413 
00414 /* Hook called by the linker routine which adds symbols from an object
00415    file.  We use it for STT_REGISTER symbols.  */
00416 
00417 static bfd_boolean
00418 elf64_sparc_add_symbol_hook (bfd *abfd, struct bfd_link_info *info,
00419                           Elf_Internal_Sym *sym, const char **namep,
00420                           flagword *flagsp ATTRIBUTE_UNUSED,
00421                           asection **secp ATTRIBUTE_UNUSED,
00422                           bfd_vma *valp ATTRIBUTE_UNUSED)
00423 {
00424   static const char *const stt_types[] = { "NOTYPE", "OBJECT", "FUNCTION" };
00425 
00426   if (ELF_ST_TYPE (sym->st_info) == STT_REGISTER)
00427     {
00428       int reg;
00429       struct _bfd_sparc_elf_app_reg *p;
00430 
00431       reg = (int)sym->st_value;
00432       switch (reg & ~1)
00433        {
00434        case 2: reg -= 2; break;
00435        case 6: reg -= 4; break;
00436        default:
00437           (*_bfd_error_handler)
00438             (_("%B: Only registers %%g[2367] can be declared using STT_REGISTER"),
00439              abfd);
00440          return FALSE;
00441        }
00442 
00443       if (info->hash->creator != abfd->xvec
00444          || (abfd->flags & DYNAMIC) != 0)
00445         {
00446          /* STT_REGISTER only works when linking an elf64_sparc object.
00447             If STT_REGISTER comes from a dynamic object, don't put it into
00448             the output bfd.  The dynamic linker will recheck it.  */
00449          *namep = NULL;
00450          return TRUE;
00451         }
00452 
00453       p = _bfd_sparc_elf_hash_table(info)->app_regs + reg;
00454 
00455       if (p->name != NULL && strcmp (p->name, *namep))
00456        {
00457           (*_bfd_error_handler)
00458             (_("Register %%g%d used incompatibly: %s in %B, previously %s in %B"),
00459              abfd, p->abfd, (int) sym->st_value,
00460              **namep ? *namep : "#scratch",
00461              *p->name ? p->name : "#scratch");
00462          return FALSE;
00463        }
00464 
00465       if (p->name == NULL)
00466        {
00467          if (**namep)
00468            {
00469              struct elf_link_hash_entry *h;
00470 
00471              h = (struct elf_link_hash_entry *)
00472               bfd_link_hash_lookup (info->hash, *namep, FALSE, FALSE, FALSE);
00473 
00474              if (h != NULL)
00475               {
00476                 unsigned char type = h->type;
00477 
00478                 if (type > STT_FUNC)
00479                   type = 0;
00480                 (*_bfd_error_handler)
00481                   (_("Symbol `%s' has differing types: REGISTER in %B, previously %s in %B"),
00482                    abfd, p->abfd, *namep, stt_types[type]);
00483                 return FALSE;
00484               }
00485 
00486              p->name = bfd_hash_allocate (&info->hash->table,
00487                                       strlen (*namep) + 1);
00488              if (!p->name)
00489               return FALSE;
00490 
00491              strcpy (p->name, *namep);
00492            }
00493          else
00494            p->name = "";
00495          p->bind = ELF_ST_BIND (sym->st_info);
00496          p->abfd = abfd;
00497          p->shndx = sym->st_shndx;
00498        }
00499       else
00500        {
00501          if (p->bind == STB_WEAK
00502              && ELF_ST_BIND (sym->st_info) == STB_GLOBAL)
00503            {
00504              p->bind = STB_GLOBAL;
00505              p->abfd = abfd;
00506            }
00507        }
00508       *namep = NULL;
00509       return TRUE;
00510     }
00511   else if (*namep && **namep
00512           && info->hash->creator == abfd->xvec)
00513     {
00514       int i;
00515       struct _bfd_sparc_elf_app_reg *p;
00516 
00517       p = _bfd_sparc_elf_hash_table(info)->app_regs;
00518       for (i = 0; i < 4; i++, p++)
00519        if (p->name != NULL && ! strcmp (p->name, *namep))
00520          {
00521            unsigned char type = ELF_ST_TYPE (sym->st_info);
00522 
00523            if (type > STT_FUNC)
00524              type = 0;
00525            (*_bfd_error_handler)
00526              (_("Symbol `%s' has differing types: %s in %B, previously REGISTER in %B"),
00527               abfd, p->abfd, *namep, stt_types[type]);
00528            return FALSE;
00529          }
00530     }
00531   return TRUE;
00532 }
00533 
00534 /* This function takes care of emitting STT_REGISTER symbols
00535    which we cannot easily keep in the symbol hash table.  */
00536 
00537 static bfd_boolean
00538 elf64_sparc_output_arch_syms (bfd *output_bfd ATTRIBUTE_UNUSED,
00539                            struct bfd_link_info *info,
00540                            PTR finfo, bfd_boolean (*func) (PTR, const char *,
00541                                                        Elf_Internal_Sym *,
00542                                                        asection *,
00543                                                        struct elf_link_hash_entry *))
00544 {
00545   int reg;
00546   struct _bfd_sparc_elf_app_reg *app_regs =
00547     _bfd_sparc_elf_hash_table(info)->app_regs;
00548   Elf_Internal_Sym sym;
00549 
00550   /* We arranged in size_dynamic_sections to put the STT_REGISTER entries
00551      at the end of the dynlocal list, so they came at the end of the local
00552      symbols in the symtab.  Except that they aren't STB_LOCAL, so we need
00553      to back up symtab->sh_info.  */
00554   if (elf_hash_table (info)->dynlocal)
00555     {
00556       bfd * dynobj = elf_hash_table (info)->dynobj;
00557       asection *dynsymsec = bfd_get_section_by_name (dynobj, ".dynsym");
00558       struct elf_link_local_dynamic_entry *e;
00559 
00560       for (e = elf_hash_table (info)->dynlocal; e ; e = e->next)
00561        if (e->input_indx == -1)
00562          break;
00563       if (e)
00564        {
00565          elf_section_data (dynsymsec->output_section)->this_hdr.sh_info
00566            = e->dynindx;
00567        }
00568     }
00569 
00570   if (info->strip == strip_all)
00571     return TRUE;
00572 
00573   for (reg = 0; reg < 4; reg++)
00574     if (app_regs [reg].name != NULL)
00575       {
00576        if (info->strip == strip_some
00577            && bfd_hash_lookup (info->keep_hash,
00578                             app_regs [reg].name,
00579                             FALSE, FALSE) == NULL)
00580          continue;
00581 
00582        sym.st_value = reg < 2 ? reg + 2 : reg + 4;
00583        sym.st_size = 0;
00584        sym.st_other = 0;
00585        sym.st_info = ELF_ST_INFO (app_regs [reg].bind, STT_REGISTER);
00586        sym.st_shndx = app_regs [reg].shndx;
00587        if (! (*func) (finfo, app_regs [reg].name, &sym,
00588                      sym.st_shndx == SHN_ABS
00589                       ? bfd_abs_section_ptr : bfd_und_section_ptr,
00590                      NULL))
00591          return FALSE;
00592       }
00593 
00594   return TRUE;
00595 }
00596 
00597 static int
00598 elf64_sparc_get_symbol_type (Elf_Internal_Sym *elf_sym, int type)
00599 {
00600   if (ELF_ST_TYPE (elf_sym->st_info) == STT_REGISTER)
00601     return STT_REGISTER;
00602   else
00603     return type;
00604 }
00605 
00606 /* A STB_GLOBAL,STT_REGISTER symbol should be BSF_GLOBAL
00607    even in SHN_UNDEF section.  */
00608 
00609 static void
00610 elf64_sparc_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, asymbol *asym)
00611 {
00612   elf_symbol_type *elfsym;
00613 
00614   elfsym = (elf_symbol_type *) asym;
00615   if (elfsym->internal_elf_sym.st_info
00616       == ELF_ST_INFO (STB_GLOBAL, STT_REGISTER))
00617     {
00618       asym->flags |= BSF_GLOBAL;
00619     }
00620 }
00621 
00622 
00623 /* Functions for dealing with the e_flags field.  */
00624 
00625 /* Merge backend specific data from an object file to the output
00626    object file when linking.  */
00627 
00628 static bfd_boolean
00629 elf64_sparc_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
00630 {
00631   bfd_boolean error;
00632   flagword new_flags, old_flags;
00633   int new_mm, old_mm;
00634 
00635   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
00636       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
00637     return TRUE;
00638 
00639   new_flags = elf_elfheader (ibfd)->e_flags;
00640   old_flags = elf_elfheader (obfd)->e_flags;
00641 
00642   if (!elf_flags_init (obfd))   /* First call, no flags set */
00643     {
00644       elf_flags_init (obfd) = TRUE;
00645       elf_elfheader (obfd)->e_flags = new_flags;
00646     }
00647 
00648   else if (new_flags == old_flags)      /* Compatible flags are ok */
00649     ;
00650 
00651   else                                  /* Incompatible flags */
00652     {
00653       error = FALSE;
00654 
00655 #define EF_SPARC_ISA_EXTENSIONS \
00656   (EF_SPARC_SUN_US1 | EF_SPARC_SUN_US3 | EF_SPARC_HAL_R1)
00657 
00658       if ((ibfd->flags & DYNAMIC) != 0)
00659        {
00660          /* We don't want dynamic objects memory ordering and
00661             architecture to have any role. That's what dynamic linker
00662             should do.  */
00663          new_flags &= ~(EF_SPARCV9_MM | EF_SPARC_ISA_EXTENSIONS);
00664          new_flags |= (old_flags
00665                      & (EF_SPARCV9_MM | EF_SPARC_ISA_EXTENSIONS));
00666        }
00667       else
00668        {
00669          /* Choose the highest architecture requirements.  */
00670          old_flags |= (new_flags & EF_SPARC_ISA_EXTENSIONS);
00671          new_flags |= (old_flags & EF_SPARC_ISA_EXTENSIONS);
00672          if ((old_flags & (EF_SPARC_SUN_US1 | EF_SPARC_SUN_US3))
00673              && (old_flags & EF_SPARC_HAL_R1))
00674            {
00675              error = TRUE;
00676              (*_bfd_error_handler)
00677               (_("%B: linking UltraSPARC specific with HAL specific code"),
00678                ibfd);
00679            }
00680          /* Choose the most restrictive memory ordering.  */
00681          old_mm = (old_flags & EF_SPARCV9_MM);
00682          new_mm = (new_flags & EF_SPARCV9_MM);
00683          old_flags &= ~EF_SPARCV9_MM;
00684          new_flags &= ~EF_SPARCV9_MM;
00685          if (new_mm < old_mm)
00686            old_mm = new_mm;
00687          old_flags |= old_mm;
00688          new_flags |= old_mm;
00689        }
00690 
00691       /* Warn about any other mismatches */
00692       if (new_flags != old_flags)
00693         {
00694           error = TRUE;
00695           (*_bfd_error_handler)
00696             (_("%B: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
00697              ibfd, (long) new_flags, (long) old_flags);
00698         }
00699 
00700       elf_elfheader (obfd)->e_flags = old_flags;
00701 
00702       if (error)
00703         {
00704           bfd_set_error (bfd_error_bad_value);
00705           return FALSE;
00706         }
00707     }
00708   return TRUE;
00709 }
00710 
00711 /* MARCO: Set the correct entry size for the .stab section.  */
00712 
00713 static bfd_boolean
00714 elf64_sparc_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
00715                         Elf_Internal_Shdr *hdr ATTRIBUTE_UNUSED,
00716                         asection *sec)
00717 {
00718   const char *name;
00719 
00720   name = bfd_get_section_name (abfd, sec);
00721 
00722   if (strcmp (name, ".stab") == 0)
00723     {
00724       /* Even in the 64bit case the stab entries are only 12 bytes long.  */
00725       elf_section_data (sec)->this_hdr.sh_entsize = 12;
00726     }
00727 
00728   return TRUE;
00729 }
00730 
00731 /* Print a STT_REGISTER symbol to file FILE.  */
00732 
00733 static const char *
00734 elf64_sparc_print_symbol_all (bfd *abfd ATTRIBUTE_UNUSED, PTR filep,
00735                            asymbol *symbol)
00736 {
00737   FILE *file = (FILE *) filep;
00738   int reg, type;
00739 
00740   if (ELF_ST_TYPE (((elf_symbol_type *) symbol)->internal_elf_sym.st_info)
00741       != STT_REGISTER)
00742     return NULL;
00743 
00744   reg = ((elf_symbol_type *) symbol)->internal_elf_sym.st_value;
00745   type = symbol->flags;
00746   fprintf (file, "REG_%c%c%11s%c%c    R", "GOLI" [reg / 8], '0' + (reg & 7), "",
00747                ((type & BSF_LOCAL)
00748                 ? (type & BSF_GLOBAL) ? '!' : 'l'
00749                  : (type & BSF_GLOBAL) ? 'g' : ' '),
00750                 (type & BSF_WEAK) ? 'w' : ' ');
00751   if (symbol->name == NULL || symbol->name [0] == '\0')
00752     return "#scratch";
00753   else
00754     return symbol->name;
00755 }
00756 
00757 static enum elf_reloc_type_class
00758 elf64_sparc_reloc_type_class (const Elf_Internal_Rela *rela)
00759 {
00760   switch ((int) ELF64_R_TYPE (rela->r_info))
00761     {
00762     case R_SPARC_RELATIVE:
00763       return reloc_class_relative;
00764     case R_SPARC_JMP_SLOT:
00765       return reloc_class_plt;
00766     case R_SPARC_COPY:
00767       return reloc_class_copy;
00768     default:
00769       return reloc_class_normal;
00770     }
00771 }
00772 
00773 /* Relocations in the 64 bit SPARC ELF ABI are more complex than in
00774    standard ELF, because R_SPARC_OLO10 has secondary addend in
00775    ELF64_R_TYPE_DATA field.  This structure is used to redirect the
00776    relocation handling routines.  */
00777 
00778 const struct elf_size_info elf64_sparc_size_info =
00779 {
00780   sizeof (Elf64_External_Ehdr),
00781   sizeof (Elf64_External_Phdr),
00782   sizeof (Elf64_External_Shdr),
00783   sizeof (Elf64_External_Rel),
00784   sizeof (Elf64_External_Rela),
00785   sizeof (Elf64_External_Sym),
00786   sizeof (Elf64_External_Dyn),
00787   sizeof (Elf_External_Note),
00788   4,          /* hash-table entry size.  */
00789   /* Internal relocations per external relocations.
00790      For link purposes we use just 1 internal per
00791      1 external, for assembly and slurp symbol table
00792      we use 2.  */
00793   1,
00794   64,         /* arch_size.  */
00795   3,          /* log_file_align.  */
00796   ELFCLASS64,
00797   EV_CURRENT,
00798   bfd_elf64_write_out_phdrs,
00799   bfd_elf64_write_shdrs_and_ehdr,
00800   elf64_sparc_write_relocs,
00801   bfd_elf64_swap_symbol_in,
00802   bfd_elf64_swap_symbol_out,
00803   elf64_sparc_slurp_reloc_table,
00804   bfd_elf64_slurp_symbol_table,
00805   bfd_elf64_swap_dyn_in,
00806   bfd_elf64_swap_dyn_out,
00807   bfd_elf64_swap_reloc_in,
00808   bfd_elf64_swap_reloc_out,
00809   bfd_elf64_swap_reloca_in,
00810   bfd_elf64_swap_reloca_out
00811 };
00812 
00813 #define TARGET_BIG_SYM      bfd_elf64_sparc_vec
00814 #define TARGET_BIG_NAME     "elf64-sparc"
00815 #define ELF_ARCH     bfd_arch_sparc
00816 #define ELF_MAXPAGESIZE 0x100000
00817 #define ELF_COMMONPAGESIZE 0x2000
00818 
00819 /* This is the official ABI value.  */
00820 #define ELF_MACHINE_CODE EM_SPARCV9
00821 
00822 /* This is the value that we used before the ABI was released.  */
00823 #define ELF_MACHINE_ALT1 EM_OLD_SPARCV9
00824 
00825 #define elf_backend_reloc_type_class \
00826   elf64_sparc_reloc_type_class
00827 #define bfd_elf64_get_reloc_upper_bound \
00828   elf64_sparc_get_reloc_upper_bound
00829 #define bfd_elf64_get_dynamic_reloc_upper_bound \
00830   elf64_sparc_get_dynamic_reloc_upper_bound
00831 #define bfd_elf64_canonicalize_reloc \
00832   elf64_sparc_canonicalize_reloc
00833 #define bfd_elf64_canonicalize_dynamic_reloc \
00834   elf64_sparc_canonicalize_dynamic_reloc
00835 #define elf_backend_add_symbol_hook \
00836   elf64_sparc_add_symbol_hook
00837 #define elf_backend_get_symbol_type \
00838   elf64_sparc_get_symbol_type
00839 #define elf_backend_symbol_processing \
00840   elf64_sparc_symbol_processing
00841 #define elf_backend_print_symbol_all \
00842   elf64_sparc_print_symbol_all
00843 #define elf_backend_output_arch_syms \
00844   elf64_sparc_output_arch_syms
00845 #define bfd_elf64_bfd_merge_private_bfd_data \
00846   elf64_sparc_merge_private_bfd_data
00847 #define elf_backend_fake_sections \
00848   elf64_sparc_fake_sections
00849 #define elf_backend_size_info \
00850   elf64_sparc_size_info
00851 
00852 #define elf_backend_plt_sym_val    \
00853   _bfd_sparc_elf_plt_sym_val
00854 #define bfd_elf64_bfd_link_hash_table_create \
00855   _bfd_sparc_elf_link_hash_table_create
00856 #define elf_info_to_howto \
00857   _bfd_sparc_elf_info_to_howto
00858 #define elf_backend_copy_indirect_symbol \
00859   _bfd_sparc_elf_copy_indirect_symbol
00860 #define bfd_elf64_bfd_reloc_type_lookup \
00861   _bfd_sparc_elf_reloc_type_lookup
00862 #define bfd_elf64_bfd_reloc_name_lookup \
00863   _bfd_sparc_elf_reloc_name_lookup
00864 #define bfd_elf64_bfd_relax_section \
00865   _bfd_sparc_elf_relax_section
00866 #define bfd_elf64_new_section_hook \
00867   _bfd_sparc_elf_new_section_hook
00868 
00869 #define elf_backend_create_dynamic_sections \
00870   _bfd_sparc_elf_create_dynamic_sections
00871 #define elf_backend_check_relocs \
00872   _bfd_sparc_elf_check_relocs
00873 #define elf_backend_adjust_dynamic_symbol \
00874   _bfd_sparc_elf_adjust_dynamic_symbol
00875 #define elf_backend_omit_section_dynsym \
00876   _bfd_sparc_elf_omit_section_dynsym
00877 #define elf_backend_size_dynamic_sections \
00878   _bfd_sparc_elf_size_dynamic_sections
00879 #define elf_backend_relocate_section \
00880   _bfd_sparc_elf_relocate_section
00881 #define elf_backend_finish_dynamic_symbol \
00882   _bfd_sparc_elf_finish_dynamic_symbol
00883 #define elf_backend_finish_dynamic_sections \
00884   _bfd_sparc_elf_finish_dynamic_sections
00885 
00886 #define bfd_elf64_mkobject \
00887   _bfd_sparc_elf_mkobject
00888 #define elf_backend_object_p \
00889   _bfd_sparc_elf_object_p
00890 #define elf_backend_gc_mark_hook \
00891   _bfd_sparc_elf_gc_mark_hook
00892 #define elf_backend_gc_sweep_hook \
00893   _bfd_sparc_elf_gc_sweep_hook
00894 #define elf_backend_init_index_section \
00895   _bfd_elf_init_1_index_section
00896 
00897 #define elf_backend_can_gc_sections 1
00898 #define elf_backend_can_refcount 1
00899 #define elf_backend_want_got_plt 0
00900 #define elf_backend_plt_readonly 0
00901 #define elf_backend_want_plt_sym 1
00902 #define elf_backend_got_header_size 8
00903 #define elf_backend_rela_normal 1
00904 
00905 /* Section 5.2.4 of the ABI specifies a 256-byte boundary for the table.  */
00906 #define elf_backend_plt_alignment 8
00907 
00908 #include "elf64-target.h"
00909 
00910 /* FreeBSD support */
00911 #undef  TARGET_BIG_SYM
00912 #define TARGET_BIG_SYM bfd_elf64_sparc_freebsd_vec
00913 #undef  TARGET_BIG_NAME
00914 #define TARGET_BIG_NAME "elf64-sparc-freebsd"
00915 #undef ELF_OSABI
00916 #define       ELF_OSABI ELFOSABI_FREEBSD
00917 
00918 #undef  elf_backend_post_process_headers
00919 #define elf_backend_post_process_headers  _bfd_elf_set_osabi
00920 #undef  elf64_bed
00921 #define elf64_bed                         elf64_sparc_fbsd_bed
00922 
00923 #include "elf64-target.h"
00924