blob: 657d9eec23744ebd8dc90ebced531f0e10077b5d [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Alpha specific symbolic name handling.
Roland McGrathd76bd7a2011-03-09 10:10:36 -08002 Copyright (C) 2002-2011 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02003 This file is part of elfutils.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00004 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
5
Mark Wielaardde2ed972012-06-05 17:15:16 +02006 This file is free software; you can redistribute it and/or modify
7 it under the terms of either
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00008
Mark Wielaardde2ed972012-06-05 17:15:16 +02009 * the GNU Lesser General Public License as published by the Free
10 Software Foundation; either version 3 of the License, or (at
11 your option) any later version
12
13 or
14
15 * the GNU General Public License as published by the Free
16 Software Foundation; either version 2 of the License, or (at
17 your option) any later version
18
19 or both in parallel, as here.
20
21 elfutils is distributed in the hope that it will be useful, but
Ulrich Drepper361df7d2006-04-04 21:38:57 +000022 WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 General Public License for more details.
25
Mark Wielaardde2ed972012-06-05 17:15:16 +020026 You should have received copies of the GNU General Public License and
27 the GNU Lesser General Public License along with this program. If
28 not, see <http://www.gnu.org/licenses/>. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000029
30#ifdef HAVE_CONFIG_H
31# include <config.h>
32#endif
33
34#include <elf.h>
35#include <stddef.h>
Roland McGrathd76bd7a2011-03-09 10:10:36 -080036#include <string.h>
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000037
Roland McGrathcd60ea82005-11-16 01:57:40 +000038#define BACKEND alpha_
39#include "libebl_CPU.h"
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000040
Ulrich Drepperb03b0572005-08-07 08:12:22 +000041
42const char *
43alpha_dynamic_tag_name (int64_t tag, char *buf __attribute__ ((unused)),
44 size_t len __attribute__ ((unused)))
45{
46 switch (tag)
47 {
48 case DT_ALPHA_PLTRO:
49 return "ALPHA_PLTRO";
50 default:
51 break;
52 }
53 return NULL;
54}
55
Ulrich Drepperb03b0572005-08-07 08:12:22 +000056bool
57alpha_dynamic_tag_check (int64_t tag)
58{
59 return tag == DT_ALPHA_PLTRO;
60}
61
Roland McGrathcd60ea82005-11-16 01:57:40 +000062/* Check for the simple reloc types. */
63Elf_Type
64alpha_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type)
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000065{
Roland McGrathcd60ea82005-11-16 01:57:40 +000066 switch (type)
67 {
68 case R_ALPHA_REFLONG:
69 return ELF_T_WORD;
70 case R_ALPHA_REFQUAD:
71 return ELF_T_XWORD;
72 default:
73 return ELF_T_NUM;
74 }
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000075}
Roland McGrath2be02912007-04-27 04:07:41 +000076
77
78/* Check whether SHF_MASKPROC flags are valid. */
79bool
80alpha_machine_section_flag_check (GElf_Xword sh_flags)
81{
82 return (sh_flags &~ (SHF_ALPHA_GPREL)) == 0;
83}
Roland McGrath60982e62008-04-05 00:40:51 +000084
85bool
86alpha_check_special_section (Ebl *ebl,
87 int ndx __attribute__ ((unused)),
88 const GElf_Shdr *shdr,
89 const char *sname __attribute__ ((unused)))
90{
91 if ((shdr->sh_flags
92 & (SHF_WRITE | SHF_EXECINSTR)) == (SHF_WRITE | SHF_EXECINSTR)
93 && shdr->sh_addr != 0)
94 {
95 /* This is ordinarily flagged, but is valid for an old-style PLT.
96
97 Look for the SHT_DYNAMIC section and the DT_PLTGOT tag in it.
98 Its d_ptr should match the .plt section's sh_addr. */
99
100 Elf_Scn *scn = NULL;
101 while ((scn = elf_nextscn (ebl->elf, scn)) != NULL)
102 {
103 GElf_Shdr scn_shdr;
104 if (likely (gelf_getshdr (scn, &scn_shdr) != NULL)
105 && scn_shdr.sh_type == SHT_DYNAMIC
106 && scn_shdr.sh_entsize != 0)
107 {
108 GElf_Addr pltgot = 0;
109 Elf_Data *data = elf_getdata (scn, NULL);
110 if (data != NULL)
111 for (size_t i = 0; i < data->d_size / scn_shdr.sh_entsize; ++i)
112 {
113 GElf_Dyn dyn;
114 if (unlikely (gelf_getdyn (data, i, &dyn) == NULL))
115 break;
116 if (dyn.d_tag == DT_PLTGOT)
117 pltgot = dyn.d_un.d_ptr;
118 else if (dyn.d_tag == DT_ALPHA_PLTRO && dyn.d_un.d_val != 0)
119 return false; /* This PLT should not be writable. */
120 }
121 return pltgot == shdr->sh_addr;
122 }
123 }
124 }
125
126 return false;
127}
Roland McGrathd76bd7a2011-03-09 10:10:36 -0800128
129/* Check whether given symbol's st_value and st_size are OK despite failing
130 normal checks. */
131bool
132alpha_check_special_symbol (Elf *elf __attribute__ ((unused)),
133 GElf_Ehdr *ehdr __attribute__ ((unused)),
134 const GElf_Sym *sym __attribute__ ((unused)),
135 const char *name,
136 const GElf_Shdr *destshdr __attribute__ ((unused)))
137{
138 if (name == NULL)
139 return false;
140
141 if (strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
142 /* On Alpha any place in the section is valid. */
143 return true;
144
145 return false;
146}
Mark Wielaarda062b6b2011-03-10 13:02:32 +0100147
148/* Check whether only valid bits are set on the st_other symbol flag.
149 Standard ST_VISIBILITY have already been masked off. */
150bool
151alpha_check_st_other_bits (unsigned char st_other)
152{
153 return ((((st_other & STO_ALPHA_STD_GPLOAD) == STO_ALPHA_NOPV)
154 || ((st_other & STO_ALPHA_STD_GPLOAD) == STO_ALPHA_STD_GPLOAD))
155 && (st_other &~ STO_ALPHA_STD_GPLOAD) == 0);
156}