1 /* PPC specific symbolic name handling.
2 Copyright (C) 2004, 2005, 2007 Red Hat, Inc.
3 This file is part of Red Hat elfutils.
4 Written by Ulrich Drepper <drepper@redhat.com>, 2004.
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.
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.
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.
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>. */
37 #include "libebl_CPU.h"
40 /* Check for the simple reloc types. */
42 ppc_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type)
58 ppc_dynamic_tag_name (int64_t tag, char *buf __attribute__ ((unused)),
59 size_t len __attribute__ ((unused)))
73 ppc_dynamic_tag_check (int64_t tag)
75 return tag == DT_PPC_GOT;
79 /* Look for DT_PPC_GOT. */
81 find_dyn_got (Elf *elf, GElf_Ehdr *ehdr, GElf_Addr *addr)
83 for (int i = 0; i < ehdr->e_phnum; ++i)
86 GElf_Phdr *phdr = gelf_getphdr (elf, i, &phdr_mem);
87 if (phdr == NULL || phdr->p_type != PT_DYNAMIC)
90 Elf_Scn *scn = gelf_offscn (elf, phdr->p_offset);
92 GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
93 Elf_Data *data = elf_getdata (scn, NULL);
94 if (shdr != NULL && shdr->sh_type == SHT_DYNAMIC && data != NULL)
95 for (unsigned int j = 0; j < shdr->sh_size / shdr->sh_entsize; ++j)
98 GElf_Dyn *dyn = gelf_getdyn (data, j, &dyn_mem);
99 if (dyn != NULL && dyn->d_tag == DT_PPC_GOT)
101 *addr = dyn->d_un.d_ptr;
106 /* There is only one PT_DYNAMIC entry. */
114 /* Check whether given symbol's st_value and st_size are OK despite failing
117 ppc_check_special_symbol (Elf *elf, GElf_Ehdr *ehdr, const GElf_Sym *sym,
118 const char *name, const GElf_Shdr *destshdr)
123 if (strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
125 /* In -msecure-plt mode, DT_PPC_GOT is present and must match. */
127 if (find_dyn_got (elf, ehdr, &gotaddr))
128 return sym->st_value == gotaddr;
130 /* In -mbss-plt mode, any place in the section is valid. */
134 const char *sname = elf_strptr (elf, ehdr->e_shstrndx, destshdr->sh_name);
138 if (strcmp (name, "_SDA_BASE_") == 0)
139 return (strcmp (sname, ".sdata") == 0
140 && sym->st_value == destshdr->sh_addr + 0x8000
141 && sym->st_size == 0);
143 if (strcmp (name, "_SDA2_BASE_") == 0)
144 return (strcmp (sname, ".sdata2") == 0
145 && sym->st_value == destshdr->sh_addr + 0x8000
146 && sym->st_size == 0);
152 /* Check if backend uses a bss PLT in this file. */
154 ppc_bss_plt_p (Elf *elf, GElf_Ehdr *ehdr)
157 return ! find_dyn_got (elf, ehdr, &addr);