packaging: update homepage url
[platform/upstream/elfutils.git] / backends / aarch64_symbol.c
1 /* AArch64 specific symbolic name handling.
2    Copyright (C) 2013, 2015 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>
35 #include <string.h>
36
37 #define BACKEND         aarch64_
38 #include "libebl_CPU.h"
39
40
41 /* Check for the simple reloc types.  */
42 Elf_Type
43 aarch64_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 }
58
59 /* If this is the _GLOBAL_OFFSET_TABLE_ symbol, then it should point in
60    the .got even if there is a .got.plt section.
61    https://sourceware.org/ml/libc-ports/2013-06/msg00057.html
62    https://bugzilla.redhat.com/show_bug.cgi?id=1201778
63  */
64 bool
65 aarch64_check_special_symbol (Elf *elf, GElf_Ehdr *ehdr, const GElf_Sym *sym,
66                               const char *name, const GElf_Shdr *destshdr)
67 {
68   if (name != NULL
69       && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
70     {
71       const char *sname = elf_strptr (elf, ehdr->e_shstrndx, destshdr->sh_name);
72       if (sname != NULL
73           && (strcmp (sname, ".got") == 0 || strcmp (sname, ".got.plt") == 0))
74         {
75           Elf_Scn *scn = NULL;
76           while ((scn = elf_nextscn (elf, scn)) != NULL)
77             {
78               GElf_Shdr shdr_mem;
79               GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
80               if (shdr != NULL)
81                 {
82                   sname = elf_strptr (elf, ehdr->e_shstrndx, shdr->sh_name);
83                   if (sname != NULL && strcmp (sname, ".got") == 0)
84                     return (sym->st_value >= shdr->sh_addr
85                             && sym->st_value < shdr->sh_addr + shdr->sh_size);
86                 }
87             }
88         }
89     }
90
91   return false;
92 }