1 /* PPC specific symbolic name handling.
2 Copyright (C) 2004, 2005, 2007 Red Hat, Inc.
3 This file is part of elfutils.
4 Written by Ulrich Drepper <drepper@redhat.com>, 2004.
6 This file is free software; you can redistribute it and/or modify
7 it under the terms of either
9 * 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
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
19 or both in parallel, as here.
21 elfutils is distributed in the hope that it will be useful, but
22 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.
26 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/>. */
40 #include "libebl_CPU.h"
43 /* Check for the simple reloc types. */
45 ppc_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type)
61 ppc_dynamic_tag_name (int64_t tag, char *buf __attribute__ ((unused)),
62 size_t len __attribute__ ((unused)))
76 ppc_dynamic_tag_check (int64_t tag)
78 return tag == DT_PPC_GOT;
82 /* Look for DT_PPC_GOT. */
84 find_dyn_got (Elf *elf, GElf_Ehdr *ehdr, GElf_Addr *addr)
86 for (int i = 0; i < ehdr->e_phnum; ++i)
89 GElf_Phdr *phdr = gelf_getphdr (elf, i, &phdr_mem);
90 if (phdr == NULL || phdr->p_type != PT_DYNAMIC)
93 Elf_Scn *scn = gelf_offscn (elf, phdr->p_offset);
95 GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
96 Elf_Data *data = elf_getdata (scn, NULL);
97 if (shdr != NULL && shdr->sh_type == SHT_DYNAMIC && data != NULL)
98 for (unsigned int j = 0; j < shdr->sh_size / shdr->sh_entsize; ++j)
101 GElf_Dyn *dyn = gelf_getdyn (data, j, &dyn_mem);
102 if (dyn != NULL && dyn->d_tag == DT_PPC_GOT)
104 *addr = dyn->d_un.d_ptr;
109 /* There is only one PT_DYNAMIC entry. */
117 /* Check whether given symbol's st_value and st_size are OK despite failing
120 ppc_check_special_symbol (Elf *elf, GElf_Ehdr *ehdr, const GElf_Sym *sym,
121 const char *name, const GElf_Shdr *destshdr)
126 if (strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
128 /* In -msecure-plt mode, DT_PPC_GOT is present and must match. */
130 if (find_dyn_got (elf, ehdr, &gotaddr))
131 return sym->st_value == gotaddr;
133 /* In -mbss-plt mode, any place in the section is valid. */
137 const char *sname = elf_strptr (elf, ehdr->e_shstrndx, destshdr->sh_name);
141 if (strcmp (name, "_SDA_BASE_") == 0)
142 return (strcmp (sname, ".sdata") == 0
143 && sym->st_value == destshdr->sh_addr + 0x8000
144 && sym->st_size == 0);
146 if (strcmp (name, "_SDA2_BASE_") == 0)
147 return (strcmp (sname, ".sdata2") == 0
148 && sym->st_value == destshdr->sh_addr + 0x8000
149 && sym->st_size == 0);
155 /* Check if backend uses a bss PLT in this file. */
157 ppc_bss_plt_p (Elf *elf, GElf_Ehdr *ehdr)
160 return ! find_dyn_got (elf, ehdr, &addr);