LCOV - code coverage report
Current view: top level - backends - s390_symbol.c (source / functions) Hit Total Coverage
Test: elfutils-0.189 Lines: 19 19 100.0 %
Date: 2023-08-29 13:46:25 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 14 26 53.8 %

           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                 :      18362 : s390_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type,
      43                 :            :                         int *addsub __attribute__ ((unused)))
      44                 :            : {
      45         [ -  + ]:      18362 :   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                 :        357 : s390_check_special_symbol (Elf *elf, const GElf_Sym *sym,
      66                 :            :                               const char *name, const GElf_Shdr *destshdr)
      67                 :            : {
      68         [ +  - ]:        357 :   if (name != NULL
      69         [ +  + ]:        357 :       && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
      70                 :            :     {
      71                 :         12 :       size_t shstrndx;
      72         [ +  - ]:         12 :       if (elf_getshdrstrndx (elf, &shstrndx) != 0)
      73                 :         12 :         return false;
      74                 :         12 :       const char *sname = elf_strptr (elf, shstrndx, destshdr->sh_name);
      75         [ +  - ]:         12 :       if (sname != NULL
      76   [ +  -  -  - ]:         12 :           && (strcmp (sname, ".got") == 0 || strcmp (sname, ".got.plt") == 0))
      77                 :            :         {
      78                 :            :           Elf_Scn *scn = NULL;
      79         [ +  - ]:        260 :           while ((scn = elf_nextscn (elf, scn)) != NULL)
      80                 :            :             {
      81                 :        260 :               GElf_Shdr shdr_mem;
      82                 :        260 :               GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
      83         [ +  - ]:        260 :               if (shdr != NULL)
      84                 :            :                 {
      85                 :        260 :                   sname = elf_strptr (elf, shstrndx, shdr->sh_name);
      86   [ +  -  +  + ]:        260 :                   if (sname != NULL && strcmp (sname, ".got") == 0)
      87                 :         12 :                     return (sym->st_value >= shdr->sh_addr
      88   [ +  -  -  + ]:         12 :                             && sym->st_value < shdr->sh_addr + shdr->sh_size);
      89                 :            :                 }
      90                 :            :             }
      91                 :            :         }
      92                 :            :     }
      93                 :            : 
      94                 :            :   return false;
      95                 :            : }

Generated by: LCOV version 1.16