1*7304104dSAndroid Build Coastguard Worker /* AArch64 specific symbolic name handling.
2*7304104dSAndroid Build Coastguard Worker Copyright (C) 2013, 2015, 2017 Red Hat, Inc.
3*7304104dSAndroid Build Coastguard Worker This file is part of elfutils.
4*7304104dSAndroid Build Coastguard Worker
5*7304104dSAndroid Build Coastguard Worker This file is free software; you can redistribute it and/or modify
6*7304104dSAndroid Build Coastguard Worker it under the terms of either
7*7304104dSAndroid Build Coastguard Worker
8*7304104dSAndroid Build Coastguard Worker * the GNU Lesser General Public License as published by the Free
9*7304104dSAndroid Build Coastguard Worker Software Foundation; either version 3 of the License, or (at
10*7304104dSAndroid Build Coastguard Worker your option) any later version
11*7304104dSAndroid Build Coastguard Worker
12*7304104dSAndroid Build Coastguard Worker or
13*7304104dSAndroid Build Coastguard Worker
14*7304104dSAndroid Build Coastguard Worker * the GNU General Public License as published by the Free
15*7304104dSAndroid Build Coastguard Worker Software Foundation; either version 2 of the License, or (at
16*7304104dSAndroid Build Coastguard Worker your option) any later version
17*7304104dSAndroid Build Coastguard Worker
18*7304104dSAndroid Build Coastguard Worker or both in parallel, as here.
19*7304104dSAndroid Build Coastguard Worker
20*7304104dSAndroid Build Coastguard Worker elfutils is distributed in the hope that it will be useful, but
21*7304104dSAndroid Build Coastguard Worker WITHOUT ANY WARRANTY; without even the implied warranty of
22*7304104dSAndroid Build Coastguard Worker MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23*7304104dSAndroid Build Coastguard Worker General Public License for more details.
24*7304104dSAndroid Build Coastguard Worker
25*7304104dSAndroid Build Coastguard Worker You should have received copies of the GNU General Public License and
26*7304104dSAndroid Build Coastguard Worker the GNU Lesser General Public License along with this program. If
27*7304104dSAndroid Build Coastguard Worker not, see <http://www.gnu.org/licenses/>. */
28*7304104dSAndroid Build Coastguard Worker
29*7304104dSAndroid Build Coastguard Worker #ifdef HAVE_CONFIG_H
30*7304104dSAndroid Build Coastguard Worker # include <config.h>
31*7304104dSAndroid Build Coastguard Worker #endif
32*7304104dSAndroid Build Coastguard Worker
33*7304104dSAndroid Build Coastguard Worker #include <system.h>
34*7304104dSAndroid Build Coastguard Worker
35*7304104dSAndroid Build Coastguard Worker #include <elf.h>
36*7304104dSAndroid Build Coastguard Worker #include <stddef.h>
37*7304104dSAndroid Build Coastguard Worker #include <string.h>
38*7304104dSAndroid Build Coastguard Worker
39*7304104dSAndroid Build Coastguard Worker #define BACKEND aarch64_
40*7304104dSAndroid Build Coastguard Worker #include "libebl_CPU.h"
41*7304104dSAndroid Build Coastguard Worker
42*7304104dSAndroid Build Coastguard Worker
43*7304104dSAndroid Build Coastguard Worker /* Check for the simple reloc types. */
44*7304104dSAndroid Build Coastguard Worker Elf_Type
aarch64_reloc_simple_type(Ebl * ebl,int type,int * addsub)45*7304104dSAndroid Build Coastguard Worker aarch64_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type,
46*7304104dSAndroid Build Coastguard Worker int *addsub __attribute__ ((unused)))
47*7304104dSAndroid Build Coastguard Worker {
48*7304104dSAndroid Build Coastguard Worker switch (type)
49*7304104dSAndroid Build Coastguard Worker {
50*7304104dSAndroid Build Coastguard Worker case R_AARCH64_ABS64:
51*7304104dSAndroid Build Coastguard Worker return ELF_T_XWORD;
52*7304104dSAndroid Build Coastguard Worker case R_AARCH64_ABS32:
53*7304104dSAndroid Build Coastguard Worker return ELF_T_WORD;
54*7304104dSAndroid Build Coastguard Worker case R_AARCH64_ABS16:
55*7304104dSAndroid Build Coastguard Worker return ELF_T_HALF;
56*7304104dSAndroid Build Coastguard Worker
57*7304104dSAndroid Build Coastguard Worker default:
58*7304104dSAndroid Build Coastguard Worker return ELF_T_NUM;
59*7304104dSAndroid Build Coastguard Worker }
60*7304104dSAndroid Build Coastguard Worker }
61*7304104dSAndroid Build Coastguard Worker
62*7304104dSAndroid Build Coastguard Worker /* If this is the _GLOBAL_OFFSET_TABLE_ symbol, then it should point in
63*7304104dSAndroid Build Coastguard Worker the .got even if there is a .got.plt section.
64*7304104dSAndroid Build Coastguard Worker https://sourceware.org/ml/libc-ports/2013-06/msg00057.html
65*7304104dSAndroid Build Coastguard Worker https://bugzilla.redhat.com/show_bug.cgi?id=1201778
66*7304104dSAndroid Build Coastguard Worker */
67*7304104dSAndroid Build Coastguard Worker bool
aarch64_check_special_symbol(Elf * elf,const GElf_Sym * sym,const char * name,const GElf_Shdr * destshdr)68*7304104dSAndroid Build Coastguard Worker aarch64_check_special_symbol (Elf *elf, const GElf_Sym *sym,
69*7304104dSAndroid Build Coastguard Worker const char *name, const GElf_Shdr *destshdr)
70*7304104dSAndroid Build Coastguard Worker {
71*7304104dSAndroid Build Coastguard Worker if (name != NULL
72*7304104dSAndroid Build Coastguard Worker && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
73*7304104dSAndroid Build Coastguard Worker {
74*7304104dSAndroid Build Coastguard Worker size_t shstrndx;
75*7304104dSAndroid Build Coastguard Worker if (elf_getshdrstrndx (elf, &shstrndx) != 0)
76*7304104dSAndroid Build Coastguard Worker return false;
77*7304104dSAndroid Build Coastguard Worker const char *sname = elf_strptr (elf, shstrndx, destshdr->sh_name);
78*7304104dSAndroid Build Coastguard Worker if (sname != NULL
79*7304104dSAndroid Build Coastguard Worker && (strcmp (sname, ".got") == 0 || strcmp (sname, ".got.plt") == 0))
80*7304104dSAndroid Build Coastguard Worker {
81*7304104dSAndroid Build Coastguard Worker Elf_Scn *scn = NULL;
82*7304104dSAndroid Build Coastguard Worker while ((scn = elf_nextscn (elf, scn)) != NULL)
83*7304104dSAndroid Build Coastguard Worker {
84*7304104dSAndroid Build Coastguard Worker GElf_Shdr shdr_mem;
85*7304104dSAndroid Build Coastguard Worker GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
86*7304104dSAndroid Build Coastguard Worker if (shdr != NULL)
87*7304104dSAndroid Build Coastguard Worker {
88*7304104dSAndroid Build Coastguard Worker sname = elf_strptr (elf, shstrndx, shdr->sh_name);
89*7304104dSAndroid Build Coastguard Worker if (sname != NULL && strcmp (sname, ".got") == 0)
90*7304104dSAndroid Build Coastguard Worker return (sym->st_value >= shdr->sh_addr
91*7304104dSAndroid Build Coastguard Worker && sym->st_value < shdr->sh_addr + shdr->sh_size);
92*7304104dSAndroid Build Coastguard Worker }
93*7304104dSAndroid Build Coastguard Worker }
94*7304104dSAndroid Build Coastguard Worker }
95*7304104dSAndroid Build Coastguard Worker }
96*7304104dSAndroid Build Coastguard Worker
97*7304104dSAndroid Build Coastguard Worker return false;
98*7304104dSAndroid Build Coastguard Worker }
99*7304104dSAndroid Build Coastguard Worker
100*7304104dSAndroid Build Coastguard Worker /* A data mapping symbol is a symbol with "$d" name or "$d.<any...>" name,
101*7304104dSAndroid Build Coastguard Worker STT_NOTYPE, STB_LOCAL and st_size of zero. The indicate the stat of a
102*7304104dSAndroid Build Coastguard Worker sequence of data items. */
103*7304104dSAndroid Build Coastguard Worker bool
aarch64_data_marker_symbol(const GElf_Sym * sym,const char * sname)104*7304104dSAndroid Build Coastguard Worker aarch64_data_marker_symbol (const GElf_Sym *sym, const char *sname)
105*7304104dSAndroid Build Coastguard Worker {
106*7304104dSAndroid Build Coastguard Worker return (sym != NULL && sname != NULL
107*7304104dSAndroid Build Coastguard Worker && sym->st_size == 0 && GELF_ST_BIND (sym->st_info) == STB_LOCAL
108*7304104dSAndroid Build Coastguard Worker && GELF_ST_TYPE (sym->st_info) == STT_NOTYPE
109*7304104dSAndroid Build Coastguard Worker && (strcmp (sname, "$d") == 0 || startswith (sname, "$d.")));
110*7304104dSAndroid Build Coastguard Worker }
111*7304104dSAndroid Build Coastguard Worker
112*7304104dSAndroid Build Coastguard Worker const char *
aarch64_dynamic_tag_name(int64_t tag,char * buf,size_t len)113*7304104dSAndroid Build Coastguard Worker aarch64_dynamic_tag_name (int64_t tag, char *buf __attribute__ ((unused)),
114*7304104dSAndroid Build Coastguard Worker size_t len __attribute__ ((unused)))
115*7304104dSAndroid Build Coastguard Worker {
116*7304104dSAndroid Build Coastguard Worker switch (tag)
117*7304104dSAndroid Build Coastguard Worker {
118*7304104dSAndroid Build Coastguard Worker case DT_AARCH64_BTI_PLT:
119*7304104dSAndroid Build Coastguard Worker return "AARCH64_BTI_PLT";
120*7304104dSAndroid Build Coastguard Worker case DT_AARCH64_PAC_PLT:
121*7304104dSAndroid Build Coastguard Worker return "AARCH64_PAC_PLT";
122*7304104dSAndroid Build Coastguard Worker case DT_AARCH64_VARIANT_PCS:
123*7304104dSAndroid Build Coastguard Worker return "AARCH64_VARIANT_PCS";
124*7304104dSAndroid Build Coastguard Worker default:
125*7304104dSAndroid Build Coastguard Worker break;
126*7304104dSAndroid Build Coastguard Worker }
127*7304104dSAndroid Build Coastguard Worker return NULL;
128*7304104dSAndroid Build Coastguard Worker }
129*7304104dSAndroid Build Coastguard Worker
130*7304104dSAndroid Build Coastguard Worker bool
aarch64_dynamic_tag_check(int64_t tag)131*7304104dSAndroid Build Coastguard Worker aarch64_dynamic_tag_check (int64_t tag)
132*7304104dSAndroid Build Coastguard Worker {
133*7304104dSAndroid Build Coastguard Worker return (tag == DT_AARCH64_BTI_PLT
134*7304104dSAndroid Build Coastguard Worker || tag == DT_AARCH64_PAC_PLT
135*7304104dSAndroid Build Coastguard Worker || tag == DT_AARCH64_VARIANT_PCS);
136*7304104dSAndroid Build Coastguard Worker }
137