blob: 3fdc9cf8bead297794fcfcff03435984cda76a59 [file] [log] [blame]
Petr Machata98c8a732013-11-26 03:10:31 +01001/* AArch64 specific symbolic name handling.
2 Copyright (C) 2013 Red Hat, Inc.
3 This file is part of elfutils.
4
5 This file is free software; you can redistribute it and/or modify
6 it under the terms of either
7
8 * the GNU Lesser General Public License as published by the Free
9 Software Foundation; either version 3 of the License, or (at
10 your option) any later version
11
12 or
13
14 * the GNU General Public License as published by the Free
15 Software Foundation; either version 2 of the License, or (at
16 your option) any later version
17
18 or both in parallel, as here.
19
20 elfutils is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
24
25 You should have received copies of the GNU General Public License and
26 the GNU Lesser General Public License along with this program. If
27 not, see <http://www.gnu.org/licenses/>. */
28
29#ifdef HAVE_CONFIG_H
30# include <config.h>
31#endif
32
33#include <elf.h>
34#include <stddef.h>
Mark Wielaardc2ba0782013-12-19 16:11:19 +010035#include <string.h>
Petr Machata98c8a732013-11-26 03:10:31 +010036
37#define BACKEND aarch64_
38#include "libebl_CPU.h"
39
40
41/* Check for the simple reloc types. */
42Elf_Type
43aarch64_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type)
44{
45 switch (type)
46 {
47 case R_AARCH64_ABS64:
48 return ELF_T_XWORD;
49 case R_AARCH64_ABS32:
50 return ELF_T_WORD;
51 case R_AARCH64_ABS16:
52 return ELF_T_HALF;
53
54 default:
55 return ELF_T_NUM;
56 }
57}
Mark Wielaardc2ba0782013-12-19 16:11:19 +010058
59/* If this is the _GLOBAL_OFFSET_TABLE_ symbol, then it should point to
60 .got[0] even if there is a .got.plt section. */
61bool
62aarch64_check_special_symbol (Elf *elf, GElf_Ehdr *ehdr, const GElf_Sym *sym,
63 const char *name, const GElf_Shdr *destshdr)
64{
65 if (name != NULL
66 && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
67 {
68 const char *sname = elf_strptr (elf, ehdr->e_shstrndx, destshdr->sh_name);
69 if (sname != NULL && strcmp (sname, ".got.plt") == 0)
70 {
71 Elf_Scn *scn = NULL;
72 while ((scn = elf_nextscn (elf, scn)) != NULL)
73 {
74 GElf_Shdr shdr_mem;
75 GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
Mark Wielaard0535e512014-01-14 22:14:23 +010076 if (shdr != NULL)
77 {
78 sname = elf_strptr (elf, ehdr->e_shstrndx, shdr->sh_name);
79 if (sname != NULL && strcmp (sname, ".got") == 0)
80 return sym->st_value == shdr->sh_addr;
81 }
Mark Wielaardc2ba0782013-12-19 16:11:19 +010082 }
83 }
84 }
85
86 return false;
87}