LCOV - code coverage report
Current view: top level - libebl - eblobjnote.c (source / functions) Hit Total Coverage
Test: elfutils-0.189 Lines: 190 303 62.7 %
Date: 2023-04-14 15:57:06 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 99 193 51.3 %

           Branch data     Line data    Source code
       1                 :            : /* Print contents of object file note.
       2                 :            :    Copyright (C) 2002, 2007, 2009, 2011, 2015, 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 <stdlib.h>
      37                 :            : #include <string.h>
      38                 :            : #include <libeblP.h>
      39                 :            : 
      40                 :            : #include "common.h"
      41                 :            : #include "libelfP.h"
      42                 :            : #include "libdwP.h"
      43                 :            : #include "memory-access.h"
      44                 :            : 
      45                 :            : 
      46                 :            : void
      47                 :       3201 : ebl_object_note (Ebl *ebl, uint32_t namesz, const char *name, uint32_t type,
      48                 :            :                  uint32_t descsz, const char *desc)
      49                 :            : {
      50         [ -  + ]:       3201 :   if (! ebl->object_note (name, type, descsz, desc))
      51                 :            :     {
      52                 :            :       /* The machine specific function did not know this type.  */
      53                 :            : 
      54         [ -  + ]:       3201 :       if (strcmp ("stapsdt", name) == 0)
      55                 :            :         {
      56         [ #  # ]:          0 :           if (type != 3)
      57                 :            :             {
      58                 :          0 :               printf (_("unknown SDT version %u\n"), type);
      59                 :          0 :               return;
      60                 :            :             }
      61                 :            : 
      62                 :            :           /* Descriptor starts with three addresses, pc, base ref and
      63                 :            :              semaphore.  Then three zero terminated strings provider,
      64                 :            :              name and arguments.  */
      65                 :            : 
      66                 :          0 :           union
      67                 :            :           {
      68                 :            :             Elf64_Addr a64[3];
      69                 :            :             Elf32_Addr a32[3];
      70                 :            :           } addrs;
      71                 :            : 
      72                 :          0 :           size_t addrs_size = gelf_fsize (ebl->elf, ELF_T_ADDR, 3, EV_CURRENT);
      73         [ #  # ]:          0 :           if (descsz < addrs_size + 3)
      74                 :            :             {
      75                 :          0 :             invalid_sdt:
      76                 :          0 :               printf (_("invalid SDT probe descriptor\n"));
      77                 :          0 :               return;
      78                 :            :             }
      79                 :            : 
      80                 :          0 :           Elf_Data src =
      81                 :            :             {
      82                 :            :               .d_type = ELF_T_ADDR, .d_version = EV_CURRENT,
      83                 :            :               .d_buf = (void *) desc, .d_size = addrs_size
      84                 :            :             };
      85                 :            : 
      86                 :          0 :           Elf_Data dst =
      87                 :            :             {
      88                 :            :               .d_type = ELF_T_ADDR, .d_version = EV_CURRENT,
      89                 :            :               .d_buf = &addrs, .d_size = addrs_size
      90                 :            :             };
      91                 :            : 
      92         [ #  # ]:          0 :           if (gelf_xlatetom (ebl->elf, &dst, &src,
      93                 :          0 :                              elf_getident (ebl->elf, NULL)[EI_DATA]) == NULL)
      94                 :            :             {
      95                 :          0 :               printf ("%s\n", elf_errmsg (-1));
      96                 :          0 :               return;
      97                 :            :             }
      98                 :            : 
      99                 :          0 :           const char *provider = desc + addrs_size;
     100                 :          0 :           const char *pname = memchr (provider, '\0', desc + descsz - provider);
     101         [ #  # ]:          0 :           if (pname == NULL)
     102                 :          0 :             goto invalid_sdt;
     103                 :            : 
     104                 :          0 :           ++pname;
     105                 :          0 :           const char *args = memchr (pname, '\0', desc + descsz - pname);
     106         [ #  # ]:          0 :           if (args == NULL ||
     107         [ #  # ]:          0 :               memchr (++args, '\0', desc + descsz - pname) != desc + descsz - 1)
     108                 :          0 :             goto invalid_sdt;
     109                 :            : 
     110                 :          0 :           GElf_Addr pc;
     111                 :          0 :           GElf_Addr base;
     112                 :          0 :           GElf_Addr sem;
     113         [ #  # ]:          0 :           if (gelf_getclass (ebl->elf) == ELFCLASS32)
     114                 :            :             {
     115                 :          0 :               pc = addrs.a32[0];
     116                 :          0 :               base = addrs.a32[1];
     117                 :          0 :               sem = addrs.a32[2];
     118                 :            :             }
     119                 :            :           else
     120                 :            :             {
     121                 :          0 :               pc = addrs.a64[0];
     122                 :          0 :               base = addrs.a64[1];
     123                 :          0 :               sem = addrs.a64[2];
     124                 :            :             }
     125                 :            : 
     126                 :          0 :           printf (_("    PC: "));
     127                 :          0 :           printf ("%#" PRIx64 ",", pc);
     128                 :          0 :           printf (_(" Base: "));
     129                 :          0 :           printf ("%#" PRIx64 ",", base);
     130                 :          0 :           printf (_(" Semaphore: "));
     131                 :          0 :           printf ("%#" PRIx64 "\n", sem);
     132                 :          0 :           printf (_("    Provider: "));
     133                 :          0 :           printf ("%s,", provider);
     134                 :          0 :           printf (_(" Name: "));
     135                 :          0 :           printf ("%s,", pname);
     136                 :          0 :           printf (_(" Args: "));
     137                 :          0 :           printf ("'%s'\n", args);
     138                 :          0 :           return;
     139                 :            :         }
     140                 :            : 
     141         [ +  + ]:       3201 :       if (strncmp (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX,
     142                 :            :                    strlen (ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX)) == 0
     143                 :       2934 :           && (type == NT_GNU_BUILD_ATTRIBUTE_OPEN
     144         [ +  - ]:       2934 :               || type == NT_GNU_BUILD_ATTRIBUTE_FUNC))
     145                 :            :         {
     146                 :            :           /* There might or might not be a pair of addresses in the desc.  */
     147         [ +  + ]:       2934 :           if (descsz > 0)
     148                 :            :             {
     149                 :        434 :               printf ("    Address Range: ");
     150                 :            : 
     151                 :        434 :               union
     152                 :            :               {
     153                 :            :                 Elf64_Addr a64[2];
     154                 :            :                 Elf32_Addr a32[2];
     155                 :            :               } addrs;
     156                 :            : 
     157                 :        434 :               size_t addr_size = gelf_fsize (ebl->elf, ELF_T_ADDR,
     158                 :            :                                              2, EV_CURRENT);
     159         [ -  + ]:        434 :               if (descsz != addr_size)
     160                 :        434 :                 printf ("<unknown data>\n");
     161                 :            :               else
     162                 :            :                 {
     163                 :        434 :                   Elf_Data src =
     164                 :            :                     {
     165                 :            :                      .d_type = ELF_T_ADDR, .d_version = EV_CURRENT,
     166                 :            :                      .d_buf = (void *) desc, .d_size = descsz
     167                 :            :                     };
     168                 :            : 
     169                 :        434 :                   Elf_Data dst =
     170                 :            :                     {
     171                 :            :                      .d_type = ELF_T_ADDR, .d_version = EV_CURRENT,
     172                 :            :                      .d_buf = &addrs, .d_size = descsz
     173                 :            :                     };
     174                 :            : 
     175         [ -  + ]:        434 :                   if (gelf_xlatetom (ebl->elf, &dst, &src,
     176                 :        434 :                                      elf_getident (ebl->elf,
     177                 :        434 :                                                    NULL)[EI_DATA]) == NULL)
     178                 :          0 :                     printf ("%s\n", elf_errmsg (-1));
     179                 :            :                   else
     180                 :            :                     {
     181         [ -  + ]:        434 :                       if (addr_size == 4)
     182                 :          0 :                         printf ("%#" PRIx32 " - %#" PRIx32 "\n",
     183                 :            :                                 addrs.a32[0], addrs.a32[1]);
     184                 :            :                       else
     185                 :        434 :                         printf ("%#" PRIx64 " - %#" PRIx64 "\n",
     186                 :            :                                 addrs.a64[0], addrs.a64[1]);
     187                 :            :                     }
     188                 :            :                 }
     189                 :            :             }
     190                 :            : 
     191                 :            :           /* Most data actually is inside the name.
     192                 :            :              https://fedoraproject.org/wiki/Toolchain/Watermark  */
     193                 :            : 
     194                 :            :           /* We need at least 2 chars of data to describe the
     195                 :            :              attribute and value encodings.  */
     196                 :       2934 :           const char *data = (name
     197                 :            :                               + strlen (ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX));
     198         [ -  + ]:       2934 :           if (namesz < 2)
     199                 :            :             {
     200                 :          0 :               printf ("<insufficient data>\n");
     201                 :          0 :               return;
     202                 :            :             }
     203                 :            : 
     204                 :       2934 :           printf ("    ");
     205                 :            : 
     206                 :            :           /* In most cases the value comes right after the encoding bytes.  */
     207                 :       2934 :           const char *value = &data[2];
     208   [ +  +  -  -  :       2934 :           switch (data[1])
          +  +  +  +  +  
                      - ]
     209                 :            :             {
     210                 :            :             case GNU_BUILD_ATTRIBUTE_VERSION:
     211                 :        415 :               printf ("VERSION: ");
     212                 :            :               break;
     213                 :            :             case GNU_BUILD_ATTRIBUTE_STACK_PROT:
     214                 :        212 :               printf ("STACK_PROT: ");
     215                 :            :               break;
     216                 :            :             case GNU_BUILD_ATTRIBUTE_RELRO:
     217                 :          0 :               printf ("RELRO: ");
     218                 :            :               break;
     219                 :            :             case GNU_BUILD_ATTRIBUTE_STACK_SIZE:
     220                 :          0 :               printf ("STACK_SIZE: ");
     221                 :            :               break;
     222                 :            :             case GNU_BUILD_ATTRIBUTE_TOOL:
     223                 :        193 :               printf ("TOOL: ");
     224                 :            :               break;
     225                 :            :             case GNU_BUILD_ATTRIBUTE_ABI:
     226                 :        212 :               printf ("ABI: ");
     227                 :            :               break;
     228                 :            :             case GNU_BUILD_ATTRIBUTE_PIC:
     229                 :        212 :               printf ("PIC: ");
     230                 :            :               break;
     231                 :            :             case GNU_BUILD_ATTRIBUTE_SHORT_ENUM:
     232                 :        212 :               printf ("SHORT_ENUM: ");
     233                 :            :               break;
     234                 :       1478 :             case 32 ... 126:
     235                 :       1478 :               printf ("\"%s\": ", &data[1]);
     236                 :       1478 :               value += strlen (&data[1]) + 1;
     237                 :       1478 :               break;
     238                 :            :             default:
     239                 :          0 :               printf ("<unknown>: ");
     240                 :            :               break;
     241                 :            :             }
     242                 :            : 
     243   [ +  +  +  +  :       2934 :           switch (data[0])
                      - ]
     244                 :            :             {
     245                 :       1270 :             case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC:
     246                 :            :               {
     247                 :            :                 /* Any numbers are always in (unsigned) little endian.  */
     248                 :       1270 :                 static const Dwarf dbg
     249                 :            :                   = { .other_byte_order = MY_ELFDATA != ELFDATA2LSB };
     250                 :       1270 :                 size_t bytes = namesz - (value - name);
     251                 :       1270 :                 uint64_t val;
     252         [ +  + ]:       1270 :                 if (bytes == 1)
     253                 :        422 :                   val = *(unsigned char *) value;
     254         [ +  + ]:        848 :                 else if (bytes == 2)
     255                 :        636 :                   val = read_2ubyte_unaligned (&dbg, value);
     256         [ -  + ]:        212 :                 else if (bytes == 4)
     257                 :          0 :                   val = read_4ubyte_unaligned (&dbg, value);
     258         [ +  - ]:        212 :                 else if (bytes == 8)
     259                 :        212 :                   val = read_8ubyte_unaligned (&dbg, value);
     260                 :            :                 else
     261                 :          0 :                   goto unknown;
     262                 :       1270 :                 printf ("%" PRIx64, val);
     263                 :            :               }
     264                 :            :               break;
     265                 :            :             case GNU_BUILD_ATTRIBUTE_TYPE_STRING:
     266                 :        608 :               printf ("\"%s\"", value);
     267                 :            :               break;
     268                 :            :             case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE:
     269                 :        432 :               printf ("TRUE");
     270                 :            :               break;
     271                 :            :             case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE:
     272                 :        624 :               printf ("FALSE");
     273                 :            :               break;
     274                 :            :             default:
     275                 :            :               {
     276                 :          0 :               unknown:
     277                 :          0 :                 printf ("<unknown>");
     278                 :            :               }
     279                 :            :               break;
     280                 :            :             }
     281                 :            : 
     282                 :       2934 :           printf ("\n");
     283                 :            : 
     284                 :       2934 :           return;
     285                 :            :         }
     286                 :            : 
     287                 :            :       /* NT_VERSION doesn't have any info.  All data is in the name.  */
     288         [ +  + ]:        267 :       if (descsz == 0 && type == NT_VERSION)
     289                 :            :         return;
     290                 :            : 
     291         [ -  + ]:        262 :       if (strcmp ("FDO", name) == 0 && type == NT_FDO_PACKAGING_METADATA
     292   [ #  #  #  # ]:          0 :           && descsz > 0 && desc[descsz - 1] == '\0')
     293                 :          0 :         printf("    Packaging Metadata: %.*s\n", (int) descsz, desc);
     294                 :            : 
     295                 :            :       /* Everything else should have the "GNU" owner name.  */
     296         [ +  + ]:        262 :       if (strcmp ("GNU", name) != 0)
     297                 :            :         return;
     298                 :            : 
     299   [ +  -  +  +  :        257 :       switch (type)
                      - ]
     300                 :            :         {
     301                 :        134 :         case NT_GNU_BUILD_ID:
     302   [ +  -  +  - ]:        134 :           if (strcmp (name, "GNU") == 0 && descsz > 0)
     303                 :            :             {
     304                 :        134 :               printf (_("    Build ID: "));
     305                 :        134 :               uint_fast32_t i;
     306         [ +  + ]:       2814 :               for (i = 0; i < descsz - 1; ++i)
     307                 :       2546 :                 printf ("%02" PRIx8, (uint8_t) desc[i]);
     308                 :        134 :               printf ("%02" PRIx8 "\n", (uint8_t) desc[i]);
     309                 :            :             }
     310                 :            :           break;
     311                 :            : 
     312                 :          0 :         case NT_GNU_GOLD_VERSION:
     313   [ #  #  #  # ]:          0 :           if (strcmp (name, "GNU") == 0 && descsz > 0)
     314                 :            :             /* A non-null terminated version string.  */
     315                 :          0 :             printf (_("    Linker version: %.*s\n"),
     316                 :            :                     (int) descsz, desc);
     317                 :            :           break;
     318                 :            : 
     319                 :         14 :         case NT_GNU_PROPERTY_TYPE_0:
     320   [ +  -  +  - ]:         14 :           if (strcmp (name, "GNU") == 0 && descsz > 0)
     321                 :            :             {
     322                 :            :               /* There are at least 2 words. type and datasz.  */
     323         [ +  - ]:         29 :               while (descsz >= 8)
     324                 :            :                 {
     325                 :         15 :                   struct pr_prop
     326                 :            :                   {
     327                 :            :                     GElf_Word pr_type;
     328                 :            :                     GElf_Word pr_datasz;
     329                 :            :                   } prop;
     330                 :            : 
     331                 :         15 :                   Elf_Data in =
     332                 :            :                     {
     333                 :            :                       .d_version = EV_CURRENT,
     334                 :            :                       .d_type = ELF_T_WORD,
     335                 :            :                       .d_size = 8,
     336                 :            :                       .d_buf = (void *) desc
     337                 :            :                     };
     338                 :         15 :                   Elf_Data out =
     339                 :            :                     {
     340                 :            :                       .d_version = EV_CURRENT,
     341                 :            :                       .d_type = ELF_T_WORD,
     342                 :            :                       .d_size = descsz,
     343                 :            :                       .d_buf = (void *) &prop
     344                 :            :                     };
     345                 :            : 
     346         [ -  + ]:         15 :                   if (gelf_xlatetom (ebl->elf, &out, &in,
     347                 :         15 :                                      elf_getident (ebl->elf,
     348                 :         15 :                                                    NULL)[EI_DATA]) == NULL)
     349                 :            :                     {
     350                 :          0 :                       printf ("%s\n", elf_errmsg (-1));
     351                 :          0 :                       return;
     352                 :            :                     }
     353                 :            : 
     354                 :         15 :                   desc += 8;
     355                 :         15 :                   descsz -= 8;
     356                 :            : 
     357         [ -  + ]:         15 :                   if (prop.pr_datasz > descsz)
     358                 :            :                     {
     359                 :          0 :                       printf ("BAD property datasz: %" PRId32 "\n",
     360                 :            :                               prop.pr_datasz);
     361                 :          0 :                       return;
     362                 :            :                     }
     363                 :            : 
     364                 :         15 :                   int elfclass = gelf_getclass (ebl->elf);
     365                 :         15 :                   char *elfident = elf_getident (ebl->elf, NULL);
     366                 :         15 :                   GElf_Ehdr ehdr;
     367                 :         15 :                   gelf_getehdr (ebl->elf, &ehdr);
     368                 :            : 
     369                 :            :                   /* Prefix.  */
     370                 :         15 :                   printf ("    ");
     371         [ +  + ]:         15 :                   if (prop.pr_type == GNU_PROPERTY_STACK_SIZE)
     372                 :            :                     {
     373                 :          4 :                       printf ("STACK_SIZE ");
     374                 :          4 :                       union
     375                 :            :                         {
     376                 :            :                           Elf64_Addr a64;
     377                 :            :                           Elf32_Addr a32;
     378                 :            :                         } addr;
     379   [ +  +  -  + ]:          4 :                       if ((elfclass == ELFCLASS32 && prop.pr_datasz == 4)
     380   [ +  -  +  - ]:          2 :                           || (elfclass == ELFCLASS64 && prop.pr_datasz == 8))
     381                 :            :                         {
     382                 :          4 :                           in.d_type = ELF_T_ADDR;
     383                 :          4 :                           out.d_type = ELF_T_ADDR;
     384                 :          4 :                           in.d_size = prop.pr_datasz;
     385                 :          4 :                           out.d_size = prop.pr_datasz;
     386                 :          4 :                           in.d_buf = (void *) desc;
     387                 :          4 :                           out.d_buf = (elfclass == ELFCLASS32
     388                 :            :                                        ? (void *) &addr.a32
     389                 :            :                                        : (void *) &addr.a64);
     390                 :            : 
     391         [ -  + ]:          4 :                           if (gelf_xlatetom (ebl->elf, &out, &in,
     392                 :          4 :                                              elfident[EI_DATA]) == NULL)
     393                 :            :                             {
     394                 :          0 :                               printf ("%s\n", elf_errmsg (-1));
     395                 :          0 :                               return;
     396                 :            :                             }
     397         [ +  + ]:          4 :                           if (elfclass == ELFCLASS32)
     398                 :          2 :                             printf ("%#" PRIx32 "\n", addr.a32);
     399                 :            :                           else
     400                 :          2 :                             printf ("%#" PRIx64 "\n", addr.a64);
     401                 :            :                         }
     402                 :            :                       else
     403                 :          4 :                         printf (" (garbage datasz: %" PRIx32 ")\n",
     404                 :            :                                 prop.pr_datasz);
     405                 :            :                     }
     406         [ +  + ]:         11 :                   else if (prop.pr_type == GNU_PROPERTY_NO_COPY_ON_PROTECTED)
     407                 :            :                     {
     408                 :          4 :                       printf ("NO_COPY_ON_PROTECTION");
     409         [ +  - ]:          4 :                       if (prop.pr_datasz == 0)
     410                 :          4 :                         printf ("\n");
     411                 :            :                       else
     412                 :          0 :                         printf (" (garbage datasz: %" PRIx32 ")\n",
     413                 :            :                                 prop.pr_datasz);
     414                 :            :                     }
     415                 :          7 :                   else if (prop.pr_type >= GNU_PROPERTY_LOPROC
     416         [ +  - ]:          7 :                       && prop.pr_type <= GNU_PROPERTY_HIPROC
     417                 :          7 :                       && (ehdr.e_machine == EM_386
     418         [ +  + ]:          7 :                           || ehdr.e_machine == EM_X86_64))
     419                 :            :                     {
     420                 :          6 :                       printf ("X86 ");
     421         [ +  + ]:          6 :                       if (prop.pr_type == GNU_PROPERTY_X86_FEATURE_1_AND)
     422                 :            :                         {
     423                 :          4 :                           printf ("FEATURE_1_AND: ");
     424                 :            : 
     425         [ +  - ]:          4 :                           if (prop.pr_datasz == 4)
     426                 :            :                             {
     427                 :          4 :                               GElf_Word data;
     428                 :          4 :                               in.d_type = ELF_T_WORD;
     429                 :          4 :                               out.d_type = ELF_T_WORD;
     430                 :          4 :                               in.d_size = 4;
     431                 :          4 :                               out.d_size = 4;
     432                 :          4 :                               in.d_buf = (void *) desc;
     433                 :          4 :                               out.d_buf = (void *) &data;
     434                 :            : 
     435         [ -  + ]:          4 :                               if (gelf_xlatetom (ebl->elf, &out, &in,
     436                 :          4 :                                                  elfident[EI_DATA]) == NULL)
     437                 :            :                                 {
     438                 :          0 :                                   printf ("%s\n", elf_errmsg (-1));
     439                 :          0 :                                   return;
     440                 :            :                                 }
     441                 :          4 :                               printf ("%08" PRIx32 " ", data);
     442                 :            : 
     443         [ +  - ]:          4 :                               if ((data & GNU_PROPERTY_X86_FEATURE_1_IBT)
     444                 :            :                                   != 0)
     445                 :            :                                 {
     446                 :          4 :                                   printf ("IBT");
     447                 :          4 :                                   data &= ~GNU_PROPERTY_X86_FEATURE_1_IBT;
     448         [ +  - ]:          4 :                                   if (data != 0)
     449                 :          4 :                                     printf (" ");
     450                 :            :                                 }
     451                 :            : 
     452         [ +  - ]:          4 :                               if ((data & GNU_PROPERTY_X86_FEATURE_1_SHSTK)
     453                 :            :                                   != 0)
     454                 :            :                                 {
     455                 :          4 :                                   printf ("SHSTK");
     456                 :          4 :                                   data &= ~GNU_PROPERTY_X86_FEATURE_1_SHSTK;
     457         [ -  + ]:          4 :                                   if (data != 0)
     458                 :          0 :                                     printf (" ");
     459                 :            :                                 }
     460                 :            : 
     461         [ -  + ]:          4 :                               if (data != 0)
     462                 :          4 :                                 printf ("UNKNOWN");
     463                 :            :                             }
     464                 :            :                           else
     465                 :          0 :                             printf ("<bad datasz: %" PRId32 ">",
     466                 :            :                                     prop.pr_datasz);
     467                 :            : 
     468                 :          4 :                           printf ("\n");
     469                 :            :                         }
     470                 :            :                       else
     471                 :            :                         {
     472                 :          2 :                           printf ("%#" PRIx32, prop.pr_type);
     473         [ +  - ]:          2 :                           if (prop.pr_datasz > 0)
     474                 :            :                             {
     475                 :          2 :                               printf (" data: ");
     476                 :          2 :                               size_t i;
     477         [ +  + ]:         10 :                               for (i = 0; i < prop.pr_datasz - 1; i++)
     478                 :          6 :                                 printf ("%02" PRIx8 " ", (uint8_t) desc[i]);
     479                 :          2 :                               printf ("%02" PRIx8 "\n", (uint8_t) desc[i]);
     480                 :            :                             }
     481                 :            :                         }
     482                 :            :                     }
     483         [ +  - ]:          1 :                   else if (prop.pr_type >= GNU_PROPERTY_LOPROC
     484                 :            :                            && prop.pr_type <= GNU_PROPERTY_HIPROC
     485         [ +  - ]:          1 :                            && ehdr.e_machine == EM_AARCH64)
     486                 :            :                     {
     487                 :          1 :                       printf ("AARCH64 ");
     488         [ +  - ]:          1 :                       if (prop.pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND)
     489                 :            :                         {
     490                 :          1 :                           printf ("FEATURE_1_AND: ");
     491                 :            : 
     492         [ +  - ]:          1 :                           if (prop.pr_datasz == 4)
     493                 :            :                             {
     494                 :          1 :                               GElf_Word data;
     495                 :          1 :                               in.d_type = ELF_T_WORD;
     496                 :          1 :                               out.d_type = ELF_T_WORD;
     497                 :          1 :                               in.d_size = 4;
     498                 :          1 :                               out.d_size = 4;
     499                 :          1 :                               in.d_buf = (void *) desc;
     500                 :          1 :                               out.d_buf = (void *) &data;
     501                 :            : 
     502         [ -  + ]:          1 :                               if (gelf_xlatetom (ebl->elf, &out, &in,
     503                 :          1 :                                                  elfident[EI_DATA]) == NULL)
     504                 :            :                                 {
     505                 :          0 :                                   printf ("%s\n", elf_errmsg (-1));
     506                 :          0 :                                   return;
     507                 :            :                                 }
     508                 :          1 :                               printf ("%08" PRIx32 " ", data);
     509                 :            : 
     510         [ +  - ]:          1 :                               if ((data & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)
     511                 :            :                                   != 0)
     512                 :            :                                 {
     513                 :          1 :                                   printf ("BTI");
     514                 :          1 :                                   data &= ~GNU_PROPERTY_AARCH64_FEATURE_1_BTI;
     515         [ +  - ]:          1 :                                   if (data != 0)
     516                 :          1 :                                     printf (" ");
     517                 :            :                                 }
     518                 :            : 
     519         [ +  - ]:          1 :                               if ((data & GNU_PROPERTY_AARCH64_FEATURE_1_PAC)
     520                 :            :                                   != 0)
     521                 :            :                                 {
     522                 :          1 :                                   printf ("PAC");
     523                 :          1 :                                   data &= ~GNU_PROPERTY_AARCH64_FEATURE_1_PAC;
     524         [ -  + ]:          1 :                                   if (data != 0)
     525                 :          0 :                                     printf (" ");
     526                 :            :                                 }
     527                 :            : 
     528         [ -  + ]:          1 :                               if (data != 0)
     529                 :          1 :                                 printf ("UNKNOWN");
     530                 :            :                             }
     531                 :            :                           else
     532                 :          0 :                             printf ("<bad datasz: %" PRId32 ">",
     533                 :            :                                     prop.pr_datasz);
     534                 :            : 
     535                 :          1 :                           printf ("\n");
     536                 :            :                         }
     537                 :            :                       else
     538                 :            :                         {
     539                 :          0 :                           printf ("%#" PRIx32, prop.pr_type);
     540         [ #  # ]:          0 :                           if (prop.pr_datasz > 0)
     541                 :            :                             {
     542                 :          0 :                               printf (" data: ");
     543                 :          0 :                               size_t i;
     544         [ #  # ]:          0 :                               for (i = 0; i < prop.pr_datasz - 1; i++)
     545                 :          0 :                                 printf ("%02" PRIx8 " ", (uint8_t) desc[i]);
     546                 :          0 :                               printf ("%02" PRIx8 "\n", (uint8_t) desc[i]);
     547                 :            :                             }
     548                 :            :                         }
     549                 :            :                     }
     550                 :            :                   else
     551                 :            :                     {
     552         [ #  # ]:          0 :                       if (prop.pr_type >= GNU_PROPERTY_LOPROC
     553                 :            :                           && prop.pr_type <= GNU_PROPERTY_HIPROC)
     554                 :          0 :                         printf ("proc_type %#" PRIx32, prop.pr_type);
     555         [ #  # ]:          0 :                       else if (prop.pr_type >= GNU_PROPERTY_LOUSER
     556                 :            :                           && prop.pr_type <= GNU_PROPERTY_HIUSER)
     557                 :          0 :                         printf ("app_type %#" PRIx32, prop.pr_type);
     558                 :            :                       else
     559                 :          0 :                         printf ("unknown_type %#" PRIx32, prop.pr_type);
     560                 :            : 
     561         [ #  # ]:          0 :                       if (prop.pr_datasz > 0)
     562                 :            :                         {
     563                 :          0 :                           printf (" data: ");
     564                 :          0 :                           size_t i;
     565         [ #  # ]:          0 :                           for (i = 0; i < prop.pr_datasz - 1; i++)
     566                 :          0 :                             printf ("%02" PRIx8 " ", (uint8_t) desc[i]);
     567                 :          0 :                           printf ("%02" PRIx8 "\n", (uint8_t) desc[i]);
     568                 :            :                         }
     569                 :            :                     }
     570                 :            : 
     571         [ +  + ]:         15 :                   if (elfclass == ELFCLASS32)
     572                 :          5 :                     prop.pr_datasz = NOTE_ALIGN4 (prop.pr_datasz);
     573                 :            :                   else
     574                 :         10 :                     prop.pr_datasz = NOTE_ALIGN8 (prop.pr_datasz);
     575                 :            : 
     576                 :         15 :                   desc += prop.pr_datasz;
     577         [ +  + ]:         15 :                   if (descsz > prop.pr_datasz)
     578                 :          1 :                     descsz -= prop.pr_datasz;
     579                 :            :                   else
     580                 :            :                     descsz = 0;
     581                 :            :                 }
     582                 :            :             }
     583                 :            :           break;
     584                 :            : 
     585                 :        109 :         case NT_GNU_ABI_TAG:
     586   [ +  -  +  - ]:        109 :           if (descsz >= 8 && descsz % 4 == 0)
     587                 :            :             {
     588                 :        109 :               Elf_Data in =
     589                 :            :                 {
     590                 :            :                   .d_version = EV_CURRENT,
     591                 :            :                   .d_type = ELF_T_WORD,
     592                 :            :                   .d_size = descsz,
     593                 :            :                   .d_buf = (void *) desc
     594                 :            :                 };
     595                 :            :               /* Normally NT_GNU_ABI_TAG is just 4 words (16 bytes).  If it
     596                 :            :                  is much (4*) larger dynamically allocate memory to convert.  */
     597                 :            : #define FIXED_TAG_BYTES 16
     598                 :        109 :               uint32_t sbuf[FIXED_TAG_BYTES];
     599                 :        109 :               uint32_t *buf;
     600         [ -  + ]:        109 :               if (unlikely (descsz / 4 > FIXED_TAG_BYTES))
     601                 :            :                 {
     602                 :          0 :                   buf = malloc (descsz);
     603         [ #  # ]:          0 :                   if (unlikely (buf == NULL))
     604                 :          0 :                     return;
     605                 :            :                 }
     606                 :            :               else
     607                 :            :                 buf = sbuf;
     608                 :        109 :               Elf_Data out =
     609                 :            :                 {
     610                 :            :                   .d_version = EV_CURRENT,
     611                 :            :                   .d_type = ELF_T_WORD,
     612                 :            :                   .d_size = descsz,
     613                 :            :                   .d_buf = buf
     614                 :            :                 };
     615                 :            : 
     616         [ +  - ]:        109 :               if (elf32_xlatetom (&out, &in, ebl->data) != NULL)
     617                 :            :                 {
     618                 :        109 :                   const char *os;
     619   [ -  -  -  -  :        109 :                   switch (buf[0])
                      + ]
     620                 :            :                     {
     621                 :            :                     case ELF_NOTE_OS_LINUX:
     622                 :            :                       os = "Linux";
     623                 :            :                       break;
     624                 :            : 
     625                 :          0 :                     case ELF_NOTE_OS_GNU:
     626                 :          0 :                       os = "GNU";
     627                 :          0 :                       break;
     628                 :            : 
     629                 :          0 :                     case ELF_NOTE_OS_SOLARIS2:
     630                 :          0 :                       os = "Solaris";
     631                 :          0 :                       break;
     632                 :            : 
     633                 :          0 :                     case ELF_NOTE_OS_FREEBSD:
     634                 :          0 :                       os = "FreeBSD";
     635                 :          0 :                       break;
     636                 :            : 
     637                 :          0 :                     default:
     638                 :          0 :                       os = "???";
     639                 :          0 :                       break;
     640                 :            :                     }
     641                 :            : 
     642                 :        109 :                   printf (_("    OS: %s, ABI: "), os);
     643         [ +  + ]:        436 :                   for (size_t cnt = 1; cnt < descsz / 4; ++cnt)
     644                 :            :                     {
     645         [ +  + ]:        327 :                       if (cnt > 1)
     646         [ -  + ]:        218 :                         putchar_unlocked ('.');
     647                 :        327 :                       printf ("%" PRIu32, buf[cnt]);
     648                 :            :                     }
     649         [ -  + ]:        109 :                   putchar_unlocked ('\n');
     650                 :            :                 }
     651         [ -  + ]:        109 :               if (descsz / 4 > FIXED_TAG_BYTES)
     652                 :          0 :                 free (buf);
     653                 :        109 :               break;
     654                 :            :             }
     655                 :            :           FALLTHROUGH;
     656                 :            : 
     657                 :            :         default:
     658                 :            :           /* Unknown type.  */
     659                 :            :           break;
     660                 :            :         }
     661                 :          0 :     }
     662                 :            : }

Generated by: LCOV version 1.14