LCOV - code coverage report
Current view: top level - backends - x86_64_retval.c (source / functions) Hit Total Coverage
Test: elfutils-0.191 Lines: 34 53 64.2 %
Date: 2024-04-17 19:42:11 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 18 35 51.4 %

           Branch data     Line data    Source code
       1                 :            : /* Function return value location for Linux/x86-64 ABI.
       2                 :            :    Copyright (C) 2005-2010, 2014 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 <assert.h>
      34                 :            : #include <dwarf.h>
      35                 :            : 
      36                 :            : #define BACKEND x86_64_
      37                 :            : #include "libebl_CPU.h"
      38                 :            : 
      39                 :            : 
      40                 :            : /* %rax, or pair %rax, %rdx.  */
      41                 :            : static const Dwarf_Op loc_intreg[] =
      42                 :            :   {
      43                 :            :     { .atom = DW_OP_reg0 }, { .atom = DW_OP_piece, .number = 8 },
      44                 :            :     { .atom = DW_OP_reg1 }, { .atom = DW_OP_piece, .number = 8 },
      45                 :            :   };
      46                 :            : #define nloc_intreg     1
      47                 :            : #define nloc_intregpair 4
      48                 :            : 
      49                 :            : /* %st(0), or pair %st(0), %st(1).  */
      50                 :            : static const Dwarf_Op loc_x87reg[] =
      51                 :            :   {
      52                 :            :     { .atom = DW_OP_regx, .number = 33 },
      53                 :            :     { .atom = DW_OP_piece, .number = 10 },
      54                 :            :     { .atom = DW_OP_regx, .number = 34 },
      55                 :            :     { .atom = DW_OP_piece, .number = 10 },
      56                 :            :   };
      57                 :            : #define nloc_x87reg     1
      58                 :            : #define nloc_x87regpair 4
      59                 :            : 
      60                 :            : /* %xmm0, or pair %xmm0, %xmm1.  */
      61                 :            : static const Dwarf_Op loc_ssereg[] =
      62                 :            :   {
      63                 :            :     { .atom = DW_OP_reg17 }, { .atom = DW_OP_piece, .number = 16 },
      64                 :            :     { .atom = DW_OP_reg18 }, { .atom = DW_OP_piece, .number = 16 },
      65                 :            :   };
      66                 :            : #define nloc_ssereg     1
      67                 :            : #define nloc_sseregpair 4
      68                 :            : 
      69                 :            : /* The return value is a structure and is actually stored in stack space
      70                 :            :    passed in a hidden argument by the caller.  But, the compiler
      71                 :            :    helpfully returns the address of that space in %rax.  */
      72                 :            : static const Dwarf_Op loc_aggregate[] =
      73                 :            :   {
      74                 :            :     { .atom = DW_OP_breg0, .number = 0 }
      75                 :            :   };
      76                 :            : #define nloc_aggregate 1
      77                 :            : 
      78                 :            : 
      79                 :            : int
      80                 :      30114 : x86_64_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
      81                 :            : {
      82                 :            :   /* Start with the function's type, and get the DW_AT_type attribute,
      83                 :            :      which is the type of the return value.  */
      84                 :      30114 :   Dwarf_Die die_mem, *typedie = &die_mem;
      85                 :      30114 :   int tag = dwarf_peeled_die_type (functypedie, typedie);
      86         [ +  + ]:      30114 :   if (tag <= 0)
      87                 :            :     return tag;
      88                 :            : 
      89                 :      20956 :   Dwarf_Word size;
      90   [ -  +  +  - ]:      20956 :   switch (tag)
      91                 :            :     {
      92                 :            :     case -1:
      93                 :            :       return -1;
      94                 :            : 
      95                 :          0 :     case DW_TAG_subrange_type:
      96         [ #  # ]:          0 :       if (! dwarf_hasattr_integrate (typedie, DW_AT_byte_size))
      97                 :            :         {
      98                 :          0 :           Dwarf_Attribute attr_mem, *attr;
      99                 :          0 :           attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
     100                 :          0 :           typedie = dwarf_formref_die (attr, &die_mem);
     101         [ #  # ]:          0 :           tag = DWARF_TAG_OR_RETURN (typedie);
     102                 :            :         }
     103                 :      20712 :       FALLTHROUGH;
     104                 :            : 
     105                 :            :     case DW_TAG_base_type:
     106                 :            :     case DW_TAG_enumeration_type:
     107                 :            :     CASE_POINTER:
     108                 :            :       {
     109                 :      20712 :         Dwarf_Attribute attr_mem;
     110         [ -  + ]:      20712 :         if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size,
     111                 :            :                                                    &attr_mem), &size) != 0)
     112                 :            :           {
     113         [ #  # ]:          0 :             if (dwarf_is_pointer (tag))
     114                 :          0 :               size = 8;
     115                 :            :             else
     116                 :          0 :               return -1;
     117                 :            :           }
     118                 :            :       }
     119                 :            : 
     120         [ +  + ]:      20712 :       if (tag == DW_TAG_base_type)
     121                 :            :         {
     122                 :      14966 :           Dwarf_Attribute attr_mem;
     123                 :      14966 :           Dwarf_Word encoding;
     124         [ +  - ]:      14966 :           if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding,
     125                 :            :                                                      &attr_mem),
     126                 :            :                                &encoding) != 0)
     127                 :        380 :             return -1;
     128                 :            : 
     129      [ -  +  + ]:      14966 :           switch (encoding)
     130                 :            :             {
     131                 :          0 :             case DW_ATE_complex_float:
     132      [ #  #  # ]:          0 :               switch (size)
     133                 :            :                 {
     134                 :          0 :                 case 4 * 2:     /* complex float */
     135                 :            :                 case 8 * 2:     /* complex double */
     136                 :          0 :                   *locp = loc_ssereg;
     137                 :          0 :                   return nloc_sseregpair;
     138                 :          0 :                 case 16 * 2:    /* complex long double */
     139                 :          0 :                   *locp = loc_x87reg;
     140                 :          0 :                   return nloc_x87regpair;
     141                 :            :                 }
     142                 :            :               return -2;
     143                 :            : 
     144                 :        380 :             case DW_ATE_float:
     145      [ +  +  - ]:        380 :               switch (size)
     146                 :            :                 {
     147                 :        200 :                 case 4: /* float */
     148                 :            :                 case 8: /* double */
     149                 :        200 :                   *locp = loc_ssereg;
     150                 :        200 :                   return nloc_ssereg;
     151                 :        180 :                 case 16:        /* long double */
     152                 :            :                   /* XXX distinguish __float128, which is sseregpair?? */
     153                 :        180 :                   *locp = loc_x87reg;
     154                 :        180 :                   return nloc_x87reg;
     155                 :            :                 }
     156                 :            :               return -2;
     157                 :            :             }
     158                 :            :         }
     159                 :            : 
     160                 :       5746 :     intreg:
     161                 :      20548 :       *locp = loc_intreg;
     162         [ +  + ]:      20548 :       if (size <= 8)
     163                 :            :         return nloc_intreg;
     164         [ -  + ]:        200 :       if (size <= 16)
     165                 :            :         return nloc_intregpair;
     166                 :            : 
     167                 :          0 :     large:
     168                 :         28 :       *locp = loc_aggregate;
     169                 :         28 :       return nloc_aggregate;
     170                 :            : 
     171                 :        244 :     case DW_TAG_structure_type:
     172                 :            :     case DW_TAG_class_type:
     173                 :            :     case DW_TAG_union_type:
     174                 :            :     case DW_TAG_array_type:
     175         [ -  + ]:        244 :       if (dwarf_aggregate_size (typedie, &size) != 0)
     176                 :          0 :         goto large;
     177         [ +  + ]:        244 :       if (size > 16)
     178                 :         28 :         goto large;
     179                 :            : 
     180                 :            :       /* XXX
     181                 :            :          Must examine the fields in picayune ways to determine the
     182                 :            :          actual answer.  This will be right for small C structs
     183                 :            :          containing integer types and similarly simple cases.
     184                 :            :       */
     185                 :            : 
     186                 :        216 :       goto intreg;
     187                 :            :     }
     188                 :            : 
     189                 :            :   /* XXX We don't have a good way to return specific errors from ebl calls.
     190                 :            :      This value means we do not understand the type, but it is well-formed
     191                 :            :      DWARF and might be valid.  */
     192                 :            :   return -2;
     193                 :            : }

Generated by: LCOV version 1.16