Branch data Line data Source code
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 : 36724 : s390_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type, 43 : : int *addsub __attribute__ ((unused))) 44 : : { 45 [ - + ]: 36724 : switch (type) 46 : : { 47 : : case R_390_64: 48 : : return ELF_T_SXWORD; 49 : : case R_390_32: 50 : : return ELF_T_SWORD; 51 : : case R_390_16: 52 : : return ELF_T_HALF; 53 : : case R_390_8: 54 : : return ELF_T_BYTE; 55 : : default: 56 : : return ELF_T_NUM; 57 : : } 58 : : } 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 : 824 : s390_check_special_symbol (Elf *elf, const GElf_Sym *sym, 66 : : const char *name, const GElf_Shdr *destshdr) 67 : : { 68 [ + - ]: 824 : if (name != NULL 69 [ + + ]: 824 : && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0) 70 : : { 71 : 28 : size_t shstrndx; 72 [ + - ]: 28 : if (elf_getshdrstrndx (elf, &shstrndx) != 0) 73 : 28 : return false; 74 : 28 : const char *sname = elf_strptr (elf, shstrndx, destshdr->sh_name); 75 [ + - ]: 28 : if (sname != NULL 76 [ + - - - ]: 28 : && (strcmp (sname, ".got") == 0 || strcmp (sname, ".got.plt") == 0)) 77 : : { 78 : : Elf_Scn *scn = NULL; 79 [ + - ]: 604 : while ((scn = elf_nextscn (elf, scn)) != NULL) 80 : : { 81 : 604 : GElf_Shdr shdr_mem; 82 : 604 : GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); 83 [ + - ]: 604 : if (shdr != NULL) 84 : : { 85 : 604 : sname = elf_strptr (elf, shstrndx, shdr->sh_name); 86 [ + - + + ]: 604 : if (sname != NULL && strcmp (sname, ".got") == 0) 87 : 28 : return (sym->st_value >= shdr->sh_addr 88 [ + - - + ]: 28 : && sym->st_value < shdr->sh_addr + shdr->sh_size); 89 : : } 90 : : } 91 : : } 92 : : } 93 : : 94 : : return false; 95 : : }