LCOV - code coverage report
Current view: top level - libebl - eblobjnotetypename.c (source / functions) Hit Total Coverage
Test: elfutils- Lines: 24 33 72.7 %
Date: 2020-06-11 18:20:19 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Return note type name.
       2             :    Copyright (C) 2002, 2007, 2009, 2011, 2016, 2018 Red Hat, Inc.
       3             :    This file is part of elfutils.
       4             :    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
       5             : 
       6             :    This file is free software; you can redistribute it and/or modify
       7             :    it under the terms of either
       8             : 
       9             :      * the GNU Lesser General Public License as published by the Free
      10             :        Software Foundation; either version 3 of the License, or (at
      11             :        your option) any later version
      12             : 
      13             :    or
      14             : 
      15             :      * the GNU General Public License as published by the Free
      16             :        Software Foundation; either version 2 of the License, or (at
      17             :        your option) any later version
      18             : 
      19             :    or both in parallel, as here.
      20             : 
      21             :    elfutils is distributed in the hope that it will be useful, but
      22             :    WITHOUT ANY WARRANTY; without even the implied warranty of
      23             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      24             :    General Public License for more details.
      25             : 
      26             :    You should have received copies of the GNU General Public License and
      27             :    the GNU Lesser General Public License along with this program.  If
      28             :    not, see <http://www.gnu.org/licenses/>.  */
      29             : 
      30             : #ifdef HAVE_CONFIG_H
      31             : # include <config.h>
      32             : #endif
      33             : 
      34             : #include <inttypes.h>
      35             : #include <stdio.h>
      36             : #include <string.h>
      37             : #include <libeblP.h>
      38             : 
      39             : 
      40             : const char *
      41        1038 : ebl_object_note_type_name (Ebl *ebl, const char *name, uint32_t type,
      42             :                            GElf_Word descsz,
      43             :                            char *buf, size_t len)
      44             : {
      45        1038 :   const char *res = ebl->object_note_type_name (name, type, buf, len);
      46             : 
      47        1038 :   if (res == NULL)
      48             :     {
      49        1038 :       if (strcmp (name, "stapsdt") == 0)
      50             :         {
      51           0 :           snprintf (buf, len, "Version: %" PRIu32, type);
      52           0 :           return buf;
      53             :         }
      54             : 
      55             : #define ELF_NOTE_GOPKGLIST 1
      56             : #define ELF_NOTE_GOABIHASH 2
      57             : #define ELF_NOTE_GODEPS    3
      58             : #define ELF_NOTE_GOBUILDID 4
      59             : 
      60        1038 :       static const char *goknowntypes[] =
      61             :         {
      62             : #define KNOWNSTYPE(name) [ELF_NOTE_GO##name] = #name
      63             :           KNOWNSTYPE (PKGLIST),
      64             :           KNOWNSTYPE (ABIHASH),
      65             :           KNOWNSTYPE (DEPS),
      66             :           KNOWNSTYPE (BUILDID),
      67             : #undef KNOWNSTYPE
      68             :         };
      69             : 
      70        1038 :       if (strcmp (name, "Go") == 0)
      71             :         {
      72           0 :           if (type < sizeof (goknowntypes) / sizeof (goknowntypes[0])
      73           0 :               && goknowntypes[type] != NULL)
      74             :             return goknowntypes[type];
      75             :           else
      76             :             {
      77           0 :               snprintf (buf, len, "%s: %" PRIu32, gettext ("<unknown>"), type);
      78           0 :               return buf;
      79             :             }
      80             :         }
      81             : 
      82        1038 :       if (strncmp (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX,
      83             :                    strlen (ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX)) == 0)
      84             :         {
      85             :           /* GNU Build Attribute notes (ab)use the owner name to store
      86             :              most of their data.  Don't decode everything here.  Just
      87             :              the type.*/
      88         930 :           char *t = buf;
      89         930 :           const char *gba = "GNU Build Attribute";
      90         930 :           int w = snprintf (t, len, "%s ", gba);
      91         930 :           t += w;
      92         930 :           len -= w;
      93         930 :           if (type == NT_GNU_BUILD_ATTRIBUTE_OPEN)
      94         856 :             snprintf (t, len, "OPEN");
      95          74 :           else if (type == NT_GNU_BUILD_ATTRIBUTE_FUNC)
      96          74 :             snprintf (t, len, "FUNC");
      97             :           else
      98           0 :             snprintf (t, len, "%x", type);
      99             : 
     100         930 :           return buf;
     101             :         }
     102             : 
     103         108 :       if (strcmp (name, "GNU") != 0)
     104             :         {
     105             :           /* NT_VERSION is special, all data is in the name.  */
     106           6 :           if (descsz == 0 && type == NT_VERSION)
     107             :             return "VERSION";
     108             : 
     109           1 :           snprintf (buf, len, "%s: %" PRIu32, gettext ("<unknown>"), type);
     110           1 :           return buf;
     111             :         }
     112             : 
     113             :       /* And finally all the "GNU" note types.  */
     114         102 :       static const char *knowntypes[] =
     115             :         {
     116             : #define KNOWNSTYPE(name) [NT_##name] = #name
     117             :           KNOWNSTYPE (GNU_ABI_TAG),
     118             :           KNOWNSTYPE (GNU_HWCAP),
     119             :           KNOWNSTYPE (GNU_BUILD_ID),
     120             :           KNOWNSTYPE (GNU_GOLD_VERSION),
     121             :           KNOWNSTYPE (GNU_PROPERTY_TYPE_0),
     122             :         };
     123             : 
     124             :       /* Handle standard names.  */
     125         102 :       if (type < sizeof (knowntypes) / sizeof (knowntypes[0])
     126         102 :           && knowntypes[type] != NULL)
     127             :         res = knowntypes[type];
     128             :       else
     129             :         {
     130           0 :           snprintf (buf, len, "%s: %" PRIu32, gettext ("<unknown>"), type);
     131             : 
     132           0 :           res = buf;
     133             :         }
     134             :     }
     135             : 
     136             :   return res;
     137             : }

Generated by: LCOV version 1.13