Author: emaste
Date: Sun Mar  8 21:10:16 2020
New Revision: 358782
URL: https://svnweb.freebsd.org/changeset/base/358782

Log:
  MFC r343610: elfdump: include note type names
  
  Based on a patch submitted by Dan McGregor.
  -
  MFC r343611: elfdump: fix build after r343610
  -
  MFC r343613: elfdump: use designated array initialization for note types
  
  This ensures the note type name is in the correct slot.
  
  Submitted by: kib
  -
  PR:           228290
  Sponsored by: The FreeBSD Foundation

Modified:
  stable/12/usr.bin/elfdump/elfdump.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.bin/elfdump/elfdump.c
==============================================================================
--- stable/12/usr.bin/elfdump/elfdump.c Sun Mar  8 21:07:21 2020        
(r358781)
+++ stable/12/usr.bin/elfdump/elfdump.c Sun Mar  8 21:10:16 2020        
(r358782)
@@ -316,6 +316,15 @@ static const char *p_flags[] = {
        "PF_X|PF_W|PF_R"
 };
 
+#define NT_ELEM(x)     [x] = #x,
+static const char *nt_types[] = {
+       "",
+       NT_ELEM(NT_FREEBSD_ABI_TAG)
+       NT_ELEM(NT_FREEBSD_NOINIT_TAG)
+       NT_ELEM(NT_FREEBSD_ARCH_TAG)
+       NT_ELEM(NT_FREEBSD_FEATURE_CTL)
+};
+
 /* http://www.sco.com/developers/gabi/latest/ch4.sheader.html#sh_type */
 static const char *
 sh_types(uint64_t machine, uint64_t sht) {
@@ -1052,7 +1061,9 @@ elf_print_note(Elf32_Ehdr *e, void *sh)
        u_int32_t namesz;
        u_int32_t descsz;
        u_int32_t desc;
+       u_int32_t type;
        char *n, *s;
+       const char *nt_type;
 
        offset = elf_get_off(e, sh, SH_OFFSET);
        size = elf_get_size(e, sh, SH_SIZE);
@@ -1062,9 +1073,14 @@ elf_print_note(Elf32_Ehdr *e, void *sh)
        while (n < ((char *)e + offset + size)) {
                namesz = elf_get_word(e, n, N_NAMESZ);
                descsz = elf_get_word(e, n, N_DESCSZ);
+               type = elf_get_word(e, n, N_TYPE);
+               if (type < nitems(nt_types) && nt_types[type] != NULL)
+                       nt_type = nt_types[type];
+               else
+                       nt_type = "Unknown type";
                s = n + sizeof(Elf_Note);
                desc = elf_get_word(e, n + sizeof(Elf_Note) + namesz, 0);
-               fprintf(out, "\t%s %d\n", s, desc);
+               fprintf(out, "\t%s %d (%s)\n", s, desc, nt_type);
                n += sizeof(Elf_Note) + namesz + descsz;
        }
 }
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to