blob: 27de54c04cfe4b538e4dc159a86984a06822f606 [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* SPARC specific symbolic name handling.
Roland McGrath13b69602008-04-01 02:30:05 +00002 Copyright (C) 2002, 2003, 2005, 2007, 2008 Red Hat, Inc.
Ulrich Drepper361df7d2006-04-04 21:38:57 +00003 This file is part of Red Hat elfutils.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00004 Written by Jakub Jelinek <jakub@redhat.com>, 2002.
5
Ulrich Drepper361df7d2006-04-04 21:38:57 +00006 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.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00009
Ulrich Drepper361df7d2006-04-04 21:38:57 +000010 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,
Ulrich Drepper1e9ef502006-04-04 22:29:06 +000017 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
Ulrich Drepper361df7d2006-04-04 21:38:57 +000018
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>. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000026
27#ifdef HAVE_CONFIG_H
28# include <config.h>
29#endif
30
31#include <elf.h>
32#include <stddef.h>
33
Roland McGrathcd60ea82005-11-16 01:57:40 +000034#define BACKEND sparc_
35#include "libebl_CPU.h"
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000036
Roland McGrathcd60ea82005-11-16 01:57:40 +000037/* Check for the simple reloc types. */
38Elf_Type
39sparc_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type)
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000040{
Roland McGrathcd60ea82005-11-16 01:57:40 +000041 switch (type)
42 {
43 case R_SPARC_8:
44 return ELF_T_BYTE;
45 case R_SPARC_16:
46 case R_SPARC_UA16:
47 return ELF_T_HALF;
48 case R_SPARC_32:
49 case R_SPARC_UA32:
50 return ELF_T_WORD;
51 case R_SPARC_64:
52 case R_SPARC_UA64:
53 return ELF_T_XWORD;
54 default:
55 return ELF_T_NUM;
56 }
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000057}
Ulrich Drepperb597dfa2007-10-16 05:21:27 +000058
59/* Check whether machine flags are valid. */
60bool
61sparc_machine_flag_check (GElf_Word flags)
62{
63 return ((flags &~ (EF_SPARCV9_MM
64 | EF_SPARC_LEDATA
65 | EF_SPARC_32PLUS
66 | EF_SPARC_SUN_US1
67 | EF_SPARC_SUN_US3)) == 0);
68}
Roland McGrath13b69602008-04-01 02:30:05 +000069
70bool
71sparc_check_special_section (Ebl *ebl,
72 int ndx __attribute__ ((unused)),
73 const GElf_Shdr *shdr,
74 const char *sname __attribute__ ((unused)))
75{
76 ebl=ebl;
77 if ((shdr->sh_flags & (SHF_WRITE | SHF_EXECINSTR))
78 == (SHF_WRITE | SHF_EXECINSTR))
79 {
80 /* This is ordinarily flagged, but is valid for a PLT on SPARC.
81
82 Look for the SHT_DYNAMIC section and the DT_PLTGOT tag in it.
83 Its d_ptr should match the .plt section's sh_addr. */
84
85 Elf_Scn *scn = NULL;
86 while ((scn = elf_nextscn (ebl->elf, scn)) != NULL)
87 {
88 GElf_Shdr scn_shdr;
89 if (likely (gelf_getshdr (scn, &scn_shdr) != NULL)
90 && scn_shdr.sh_type == SHT_DYNAMIC
91 && scn_shdr.sh_entsize != 0)
92 {
93 Elf_Data *data = elf_getdata (scn, NULL);
94 if (data != NULL)
95 for (size_t i = 0; i < data->d_size / scn_shdr.sh_entsize; ++i)
96 {
97 GElf_Dyn dyn;
98 if (unlikely (gelf_getdyn (data, i, &dyn) == NULL))
99 break;
100 if (dyn.d_tag == DT_PLTGOT)
101 return dyn.d_un.d_ptr == shdr->sh_addr;
102 }
103 break;
104 }
105 }
106 }
107
108 return false;
109}
110
111const char *
112sparc_symbol_type_name (int type,
113 char *buf __attribute__ ((unused)),
114 size_t len __attribute__ ((unused)))
115{
116 switch (type)
117 {
118 case STT_SPARC_REGISTER:
119 return "SPARC_REGISTER";
120 }
121 return NULL;
122}
123
124const char *
125sparc_dynamic_tag_name (int64_t tag,
126 char *buf __attribute__ ((unused)),
127 size_t len __attribute__ ((unused)))
128{
129 switch (tag)
130 {
131 case DT_SPARC_REGISTER:
132 return "SPARC_REGISTER";
133 }
134 return NULL;
135}
136
137bool
138sparc_dynamic_tag_check (int64_t tag)
139{
140 switch (tag)
141 {
142 case DT_SPARC_REGISTER:
143 return true;
144 }
145 return false;
146}