1*7304104dSAndroid Build Coastguard Worker /* S/390-specific symbolic name handling.
2*7304104dSAndroid Build Coastguard Worker Copyright (C) 2005 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 <elf.h>
34*7304104dSAndroid Build Coastguard Worker #include <stddef.h>
35*7304104dSAndroid Build Coastguard Worker #include <string.h>
36*7304104dSAndroid Build Coastguard Worker
37*7304104dSAndroid Build Coastguard Worker #define BACKEND s390_
38*7304104dSAndroid Build Coastguard Worker #include "libebl_CPU.h"
39*7304104dSAndroid Build Coastguard Worker
40*7304104dSAndroid Build Coastguard Worker /* Check for the simple reloc types. */
41*7304104dSAndroid Build Coastguard Worker Elf_Type
s390_reloc_simple_type(Ebl * ebl,int type,int * addsub)42*7304104dSAndroid Build Coastguard Worker s390_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type,
43*7304104dSAndroid Build Coastguard Worker int *addsub __attribute__ ((unused)))
44*7304104dSAndroid Build Coastguard Worker {
45*7304104dSAndroid Build Coastguard Worker switch (type)
46*7304104dSAndroid Build Coastguard Worker {
47*7304104dSAndroid Build Coastguard Worker case R_390_64:
48*7304104dSAndroid Build Coastguard Worker return ELF_T_SXWORD;
49*7304104dSAndroid Build Coastguard Worker case R_390_32:
50*7304104dSAndroid Build Coastguard Worker return ELF_T_SWORD;
51*7304104dSAndroid Build Coastguard Worker case R_390_16:
52*7304104dSAndroid Build Coastguard Worker return ELF_T_HALF;
53*7304104dSAndroid Build Coastguard Worker case R_390_8:
54*7304104dSAndroid Build Coastguard Worker return ELF_T_BYTE;
55*7304104dSAndroid Build Coastguard Worker default:
56*7304104dSAndroid Build Coastguard Worker return ELF_T_NUM;
57*7304104dSAndroid Build Coastguard Worker }
58*7304104dSAndroid Build Coastguard Worker }
59*7304104dSAndroid Build Coastguard Worker
60*7304104dSAndroid Build Coastguard Worker /* The _GLOBAL_OFFSET_TABLE_ symbol might point to the DT_PLTGOT,
61*7304104dSAndroid Build Coastguard Worker which is in the .got section, even if the symbol itself is
62*7304104dSAndroid Build Coastguard Worker associated with the is a .got.plt section.
63*7304104dSAndroid Build Coastguard Worker https://sourceware.org/ml/binutils/2018-07/msg00200.html */
64*7304104dSAndroid Build Coastguard Worker bool
s390_check_special_symbol(Elf * elf,const GElf_Sym * sym,const char * name,const GElf_Shdr * destshdr)65*7304104dSAndroid Build Coastguard Worker s390_check_special_symbol (Elf *elf, const GElf_Sym *sym,
66*7304104dSAndroid Build Coastguard Worker const char *name, const GElf_Shdr *destshdr)
67*7304104dSAndroid Build Coastguard Worker {
68*7304104dSAndroid Build Coastguard Worker if (name != NULL
69*7304104dSAndroid Build Coastguard Worker && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
70*7304104dSAndroid Build Coastguard Worker {
71*7304104dSAndroid Build Coastguard Worker size_t shstrndx;
72*7304104dSAndroid Build Coastguard Worker if (elf_getshdrstrndx (elf, &shstrndx) != 0)
73*7304104dSAndroid Build Coastguard Worker return false;
74*7304104dSAndroid Build Coastguard Worker const char *sname = elf_strptr (elf, shstrndx, destshdr->sh_name);
75*7304104dSAndroid Build Coastguard Worker if (sname != NULL
76*7304104dSAndroid Build Coastguard Worker && (strcmp (sname, ".got") == 0 || strcmp (sname, ".got.plt") == 0))
77*7304104dSAndroid Build Coastguard Worker {
78*7304104dSAndroid Build Coastguard Worker Elf_Scn *scn = NULL;
79*7304104dSAndroid Build Coastguard Worker while ((scn = elf_nextscn (elf, scn)) != NULL)
80*7304104dSAndroid Build Coastguard Worker {
81*7304104dSAndroid Build Coastguard Worker GElf_Shdr shdr_mem;
82*7304104dSAndroid Build Coastguard Worker GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
83*7304104dSAndroid Build Coastguard Worker if (shdr != NULL)
84*7304104dSAndroid Build Coastguard Worker {
85*7304104dSAndroid Build Coastguard Worker sname = elf_strptr (elf, shstrndx, shdr->sh_name);
86*7304104dSAndroid Build Coastguard Worker if (sname != NULL && strcmp (sname, ".got") == 0)
87*7304104dSAndroid Build Coastguard Worker return (sym->st_value >= shdr->sh_addr
88*7304104dSAndroid Build Coastguard Worker && sym->st_value < shdr->sh_addr + shdr->sh_size);
89*7304104dSAndroid Build Coastguard Worker }
90*7304104dSAndroid Build Coastguard Worker }
91*7304104dSAndroid Build Coastguard Worker }
92*7304104dSAndroid Build Coastguard Worker }
93*7304104dSAndroid Build Coastguard Worker
94*7304104dSAndroid Build Coastguard Worker return false;
95*7304104dSAndroid Build Coastguard Worker }
96