1 /* Alpha specific symbolic name handling.
2 Copyright (C) 2002,2005,2007,2008 Red Hat, Inc.
3 This file is part of Red Hat elfutils.
4 Written by Ulrich Drepper <drepper@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
34 #define BACKEND alpha_
35 #include "libebl_CPU.h"
36
37
38 const char *
alpha_dynamic_tag_name(int64_t tag,char * buf,size_t len)39 alpha_dynamic_tag_name (int64_t tag, char *buf __attribute__ ((unused)),
40 size_t len __attribute__ ((unused)))
41 {
42 switch (tag)
43 {
44 case DT_ALPHA_PLTRO:
45 return "ALPHA_PLTRO";
46 default:
47 break;
48 }
49 return NULL;
50 }
51
52 bool
alpha_dynamic_tag_check(int64_t tag)53 alpha_dynamic_tag_check (int64_t tag)
54 {
55 return tag == DT_ALPHA_PLTRO;
56 }
57
58 /* Check for the simple reloc types. */
59 Elf_Type
alpha_reloc_simple_type(Ebl * ebl,int type)60 alpha_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type)
61 {
62 switch (type)
63 {
64 case R_ALPHA_REFLONG:
65 return ELF_T_WORD;
66 case R_ALPHA_REFQUAD:
67 return ELF_T_XWORD;
68 default:
69 return ELF_T_NUM;
70 }
71 }
72
73
74 /* Check whether SHF_MASKPROC flags are valid. */
75 bool
alpha_machine_section_flag_check(GElf_Xword sh_flags)76 alpha_machine_section_flag_check (GElf_Xword sh_flags)
77 {
78 return (sh_flags &~ (SHF_ALPHA_GPREL)) == 0;
79 }
80
81 bool
alpha_check_special_section(Ebl * ebl,int ndx,const GElf_Shdr * shdr,const char * sname)82 alpha_check_special_section (Ebl *ebl,
83 int ndx __attribute__ ((unused)),
84 const GElf_Shdr *shdr,
85 const char *sname __attribute__ ((unused)))
86 {
87 if ((shdr->sh_flags
88 & (SHF_WRITE | SHF_EXECINSTR)) == (SHF_WRITE | SHF_EXECINSTR)
89 && shdr->sh_addr != 0)
90 {
91 /* This is ordinarily flagged, but is valid for an old-style PLT.
92
93 Look for the SHT_DYNAMIC section and the DT_PLTGOT tag in it.
94 Its d_ptr should match the .plt section's sh_addr. */
95
96 Elf_Scn *scn = NULL;
97 while ((scn = elf_nextscn (ebl->elf, scn)) != NULL)
98 {
99 GElf_Shdr scn_shdr;
100 if (likely (gelf_getshdr (scn, &scn_shdr) != NULL)
101 && scn_shdr.sh_type == SHT_DYNAMIC
102 && scn_shdr.sh_entsize != 0)
103 {
104 GElf_Addr pltgot = 0;
105 Elf_Data *data = elf_getdata (scn, NULL);
106 if (data != NULL)
107 for (size_t i = 0; i < data->d_size / scn_shdr.sh_entsize; ++i)
108 {
109 GElf_Dyn dyn;
110 if (unlikely (gelf_getdyn (data, i, &dyn) == NULL))
111 break;
112 if (dyn.d_tag == DT_PLTGOT)
113 pltgot = dyn.d_un.d_ptr;
114 else if (dyn.d_tag == DT_ALPHA_PLTRO && dyn.d_un.d_val != 0)
115 return false; /* This PLT should not be writable. */
116 }
117 return pltgot == shdr->sh_addr;
118 }
119 }
120 }
121
122 return false;
123 }
124