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