Home | History | Annotate | Download | only in backends
      1 /* Alpha specific symbolic name handling.
      2    Copyright (C) 2002-2011 Red Hat, Inc.
      3    This file is part of Red Hat elfutils.
      4    Written by Ulrich Drepper <drepper (at) redhat.com>, 2002.
      5 
      6    Red Hat elfutils is free software; you can redistribute it and/or modify
      7    it under the terms of the GNU General Public License as published by the
      8    Free Software Foundation; version 2 of the License.
      9 
     10    Red Hat elfutils is distributed in the hope that it will be useful, but
     11    WITHOUT ANY WARRANTY; without even the implied warranty of
     12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13    General Public License for more details.
     14 
     15    You should have received a copy of the GNU General Public License along
     16    with Red Hat elfutils; if not, write to the Free Software Foundation,
     17    Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
     18 
     19    Red Hat elfutils is an included package of the Open Invention Network.
     20    An included package of the Open Invention Network is a package for which
     21    Open Invention Network licensees cross-license their patents.  No patent
     22    license is granted, either expressly or impliedly, by designation as an
     23    included package.  Should you wish to participate in the Open Invention
     24    Network licensing program, please visit www.openinventionnetwork.com
     25    <http://www.openinventionnetwork.com>.  */
     26 
     27 #ifdef HAVE_CONFIG_H
     28 # include <config.h>
     29 #endif
     30 
     31 #include <elf.h>
     32 #include <stddef.h>
     33 #include <string.h>
     34 
     35 #define BACKEND		alpha_
     36 #include "libebl_CPU.h"
     37 
     38 
     39 const char *
     40 alpha_dynamic_tag_name (int64_t tag, char *buf __attribute__ ((unused)),
     41 			size_t len __attribute__ ((unused)))
     42 {
     43   switch (tag)
     44     {
     45     case DT_ALPHA_PLTRO:
     46       return "ALPHA_PLTRO";
     47     default:
     48       break;
     49     }
     50   return NULL;
     51 }
     52 
     53 bool
     54 alpha_dynamic_tag_check (int64_t tag)
     55 {
     56   return tag == DT_ALPHA_PLTRO;
     57 }
     58 
     59 /* Check for the simple reloc types.  */
     60 Elf_Type
     61 alpha_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type)
     62 {
     63   switch (type)
     64     {
     65     case R_ALPHA_REFLONG:
     66       return ELF_T_WORD;
     67     case R_ALPHA_REFQUAD:
     68       return ELF_T_XWORD;
     69     default:
     70       return ELF_T_NUM;
     71     }
     72 }
     73 
     74 
     75 /* Check whether SHF_MASKPROC flags are valid.  */
     76 bool
     77 alpha_machine_section_flag_check (GElf_Xword sh_flags)
     78 {
     79   return (sh_flags &~ (SHF_ALPHA_GPREL)) == 0;
     80 }
     81 
     82 bool
     83 alpha_check_special_section (Ebl *ebl,
     84 			     int ndx __attribute__ ((unused)),
     85 			     const GElf_Shdr *shdr,
     86 			     const char *sname __attribute__ ((unused)))
     87 {
     88   if ((shdr->sh_flags
     89        & (SHF_WRITE | SHF_EXECINSTR)) == (SHF_WRITE | SHF_EXECINSTR)
     90       && shdr->sh_addr != 0)
     91     {
     92       /* This is ordinarily flagged, but is valid for an old-style PLT.
     93 
     94 	 Look for the SHT_DYNAMIC section and the DT_PLTGOT tag in it.
     95 	 Its d_ptr should match the .plt section's sh_addr.  */
     96 
     97       Elf_Scn *scn = NULL;
     98       while ((scn = elf_nextscn (ebl->elf, scn)) != NULL)
     99 	{
    100 	  GElf_Shdr scn_shdr;
    101 	  if (likely (gelf_getshdr (scn, &scn_shdr) != NULL)
    102 	      && scn_shdr.sh_type == SHT_DYNAMIC
    103 	      && scn_shdr.sh_entsize != 0)
    104 	    {
    105 	      GElf_Addr pltgot = 0;
    106 	      Elf_Data *data = elf_getdata (scn, NULL);
    107 	      if (data != NULL)
    108 		for (size_t i = 0; i < data->d_size / scn_shdr.sh_entsize; ++i)
    109 		  {
    110 		    GElf_Dyn dyn;
    111 		    if (unlikely (gelf_getdyn (data, i, &dyn) == NULL))
    112 		      break;
    113 		    if (dyn.d_tag == DT_PLTGOT)
    114 		      pltgot = dyn.d_un.d_ptr;
    115 		    else if (dyn.d_tag == DT_ALPHA_PLTRO && dyn.d_un.d_val != 0)
    116 		      return false; /* This PLT should not be writable.  */
    117 		  }
    118 	      return pltgot == shdr->sh_addr;
    119 	    }
    120 	}
    121     }
    122 
    123   return false;
    124 }
    125 
    126 /* Check whether given symbol's st_value and st_size are OK despite failing
    127    normal checks.  */
    128 bool
    129 alpha_check_special_symbol (Elf *elf __attribute__ ((unused)),
    130 			    GElf_Ehdr *ehdr __attribute__ ((unused)),
    131 			    const GElf_Sym *sym __attribute__ ((unused)),
    132 			    const char *name,
    133 			    const GElf_Shdr *destshdr __attribute__ ((unused)))
    134 {
    135   if (name == NULL)
    136     return false;
    137 
    138   if (strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
    139     /* On Alpha any place in the section is valid.  */
    140     return true;
    141 
    142   return false;
    143 }
    144 
    145 /* Check whether only valid bits are set on the st_other symbol flag.
    146    Standard ST_VISIBILITY have already been masked off.  */
    147 bool
    148 alpha_check_st_other_bits (unsigned char st_other)
    149 {
    150   return ((((st_other & STO_ALPHA_STD_GPLOAD) == STO_ALPHA_NOPV)
    151 	   || ((st_other & STO_ALPHA_STD_GPLOAD) == STO_ALPHA_STD_GPLOAD))
    152 	  && (st_other &~ STO_ALPHA_STD_GPLOAD) == 0);
    153 }
    154