fd33ee5
commit 5199e15870e05e5b0b9f98c20fc9b5427aa6dd6a
fd33ee5
Author: Mark Wielaard <mark@klomp.org>
fd33ee5
Date:   Mon Oct 15 23:35:47 2018 +0200
fd33ee5
fd33ee5
    Recognize and parse GNU Property notes.
fd33ee5
    
fd33ee5
    GNU Property notes are different from normal notes because they use
fd33ee5
    variable alignment/padding of their fields. They are 8 byte aligned,
fd33ee5
    but use 4 byte fields. The name is aligned at 4 bytes and padded so
fd33ee5
    that, the desc is aligned at 8 bytes. The whole note is padded to
fd33ee5
    8 bytes again. For normal notes all fields are both 4 bytes wide and
fd33ee5
    4 bytes aligned.
fd33ee5
    
fd33ee5
    To recognize these new kind of ELF Notes a new Elf_Type is introduced,
fd33ee5
    ELF_T_NHDR8. This type is used in the xlate functions to determine
fd33ee5
    how to align and pad the various fields. Since the fields themselves
fd33ee5
    can now have different alignments we will have to keep track of the
fd33ee5
    current alignement and use either NOTE_ALIGN4 or NOTE_ALIGN8 to
fd33ee5
    determine the padding.
fd33ee5
    
fd33ee5
    To set the correct Elf_Type on the Elf_Data we use either the section
fd33ee5
    sh_addralign or the segment p_align values. Assuming 8 means the
fd33ee5
    section or segment contains the new style notes, otherwise normal
fd33ee5
    notes.
fd33ee5
    
fd33ee5
    When we cannot determine the "alignment" directly, like when parsing
fd33ee5
    special kernel sys files, we check the name "GNU" and type
fd33ee5
    "GNU_PROPERTY_TYPE_0" fields.
fd33ee5
    
fd33ee5
    ebl_object_note now parses the new NT_GNU_PROPERTY_TYPE_0 and can
fd33ee5
    extract the GNU_PROPERTY_STACK_SIZE, GNU_PROPERTY_NO_COPY_ON_PROTECTED
fd33ee5
    and GNU_PROPERTY_X86_FEATURE_1_AND types GNU_PROPERTY_X86_FEATURE_1_IBT
fd33ee5
    and GNU_PROPERTY_X86_FEATURE_1_SHSTK.
fd33ee5
    
fd33ee5
    Tests are added for extracting the note from sections or segments
fd33ee5
    as set by gcc -fcf-protection.
fd33ee5
    
fd33ee5
    Signed-off-by: Mark Wielaard <mark@klomp.org>
fd33ee5
fd33ee5
diff --git a/libdwelf/dwelf_elf_gnu_build_id.c b/libdwelf/dwelf_elf_gnu_build_id.c
fd33ee5
index 8c78c70..dbcfc82 100644
fd33ee5
--- a/libdwelf/dwelf_elf_gnu_build_id.c
fd33ee5
+++ b/libdwelf/dwelf_elf_gnu_build_id.c
fd33ee5
@@ -88,7 +88,9 @@ find_elf_build_id (Dwfl_Module *mod, int e_type, Elf *elf,
fd33ee5
 	    result = check_notes (elf_getdata_rawchunk (elf,
fd33ee5
 							phdr->p_offset,
fd33ee5
 							phdr->p_filesz,
fd33ee5
-							ELF_T_NHDR),
fd33ee5
+							(phdr->p_align == 8
fd33ee5
+							 ? ELF_T_NHDR8
fd33ee5
+							 : ELF_T_NHDR)),
fd33ee5
 				  phdr->p_vaddr,
fd33ee5
 				  build_id_bits,
fd33ee5
 				  build_id_elfaddr,
fd33ee5
diff --git a/libdwfl/core-file.c b/libdwfl/core-file.c
fd33ee5
index 84cb89a..01109f4 100644
fd33ee5
--- a/libdwfl/core-file.c
fd33ee5
+++ b/libdwfl/core-file.c
fd33ee5
@@ -496,7 +496,9 @@ dwfl_core_file_report (Dwfl *dwfl, Elf *elf, const char *executable)
fd33ee5
       Elf_Data *notes = elf_getdata_rawchunk (elf,
fd33ee5
 					      notes_phdr.p_offset,
fd33ee5
 					      notes_phdr.p_filesz,
fd33ee5
-					      ELF_T_NHDR);
fd33ee5
+					      (notes_phdr.p_align == 8
fd33ee5
+					       ? ELF_T_NHDR8
fd33ee5
+					       : ELF_T_NHDR));
fd33ee5
       if (likely (notes != NULL))
fd33ee5
 	{
fd33ee5
 	  size_t pos = 0;
fd33ee5
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
fd33ee5
index 8749884..0d633ff 100644
fd33ee5
--- a/libdwfl/dwfl_segment_report_module.c
fd33ee5
+++ b/libdwfl/dwfl_segment_report_module.c
fd33ee5
@@ -27,7 +27,7 @@
fd33ee5
    not, see <http://www.gnu.org/licenses/>.  */
fd33ee5
 
fd33ee5
 #include <config.h>
fd33ee5
-#include "../libelf/libelfP.h"	/* For NOTE_ALIGN.  */
fd33ee5
+#include "../libelf/libelfP.h"	/* For NOTE_ALIGN4 and NOTE_ALIGN8.  */
fd33ee5
 #undef	_
fd33ee5
 #include "libdwflP.h"
fd33ee5
 #include "common.h"
fd33ee5
@@ -451,7 +451,8 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
fd33ee5
   GElf_Addr build_id_vaddr = 0;
fd33ee5
 
fd33ee5
   /* Consider a PT_NOTE we've found in the image.  */
fd33ee5
-  inline void consider_notes (GElf_Addr vaddr, GElf_Xword filesz)
fd33ee5
+  inline void consider_notes (GElf_Addr vaddr, GElf_Xword filesz,
fd33ee5
+			      GElf_Xword align)
fd33ee5
   {
fd33ee5
     /* If we have already seen a build ID, we don't care any more.  */
fd33ee5
     if (build_id != NULL || filesz == 0)
fd33ee5
@@ -478,7 +479,8 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
fd33ee5
 	notes = malloc (filesz);
fd33ee5
 	if (unlikely (notes == NULL))
fd33ee5
 	  return;
fd33ee5
-	xlatefrom.d_type = xlateto.d_type = ELF_T_NHDR;
fd33ee5
+	xlatefrom.d_type = xlateto.d_type = (align == 8
fd33ee5
+					     ? ELF_T_NHDR8 : ELF_T_NHDR);
fd33ee5
 	xlatefrom.d_buf = (void *) data;
fd33ee5
 	xlatefrom.d_size = filesz;
fd33ee5
 	xlateto.d_buf = notes;
fd33ee5
@@ -489,15 +491,23 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
fd33ee5
       }
fd33ee5
 
fd33ee5
     const GElf_Nhdr *nh = notes;
fd33ee5
-    while ((const void *) nh < (const void *) notes + filesz)
fd33ee5
-     {
fd33ee5
-	const void *note_name = nh + 1;
fd33ee5
-	const void *note_desc = note_name + NOTE_ALIGN (nh->n_namesz);
fd33ee5
-	if (unlikely ((size_t) ((const void *) notes + filesz
fd33ee5
-				- note_desc) < nh->n_descsz))
fd33ee5
+    size_t len = 0;
fd33ee5
+    while (filesz > len + sizeof (*nh))
fd33ee5
+      {
fd33ee5
+	const void *note_name;
fd33ee5
+	const void *note_desc;
fd33ee5
+
fd33ee5
+	len += sizeof (*nh);
fd33ee5
+	note_name = notes + len;
fd33ee5
+
fd33ee5
+	len += nh->n_namesz;
fd33ee5
+	len = align == 8 ? NOTE_ALIGN8 (len) : NOTE_ALIGN4 (len);
fd33ee5
+	note_desc = notes + len;
fd33ee5
+
fd33ee5
+	if (unlikely (filesz < len + nh->n_descsz))
fd33ee5
 	  break;
fd33ee5
 
fd33ee5
-	if (nh->n_type == NT_GNU_BUILD_ID
fd33ee5
+        if (nh->n_type == NT_GNU_BUILD_ID
fd33ee5
 	    && nh->n_descsz > 0
fd33ee5
 	    && nh->n_namesz == sizeof "GNU"
fd33ee5
 	    && !memcmp (note_name, "GNU", sizeof "GNU"))
fd33ee5
@@ -510,7 +520,9 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
fd33ee5
 	    break;
fd33ee5
 	  }
fd33ee5
 
fd33ee5
-	nh = note_desc + NOTE_ALIGN (nh->n_descsz);
fd33ee5
+	len += nh->n_descsz;
fd33ee5
+	len = align == 8 ? NOTE_ALIGN8 (len) : NOTE_ALIGN4 (len);
fd33ee5
+	nh = (void *) notes + len;
fd33ee5
       }
fd33ee5
 
fd33ee5
   done:
fd33ee5
@@ -535,7 +547,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
fd33ee5
       case PT_NOTE:
fd33ee5
 	/* We calculate from the p_offset of the note segment,
fd33ee5
 	   because we don't yet know the bias for its p_vaddr.  */
fd33ee5
-	consider_notes (start + offset, filesz);
fd33ee5
+	consider_notes (start + offset, filesz, align);
fd33ee5
 	break;
fd33ee5
 
fd33ee5
       case PT_LOAD:
fd33ee5
diff --git a/libdwfl/linux-core-attach.c b/libdwfl/linux-core-attach.c
fd33ee5
index 9f05f72..6c99b9e 100644
fd33ee5
--- a/libdwfl/linux-core-attach.c
fd33ee5
+++ b/libdwfl/linux-core-attach.c
fd33ee5
@@ -355,7 +355,9 @@ dwfl_core_file_attach (Dwfl *dwfl, Elf *core)
fd33ee5
       if (phdr != NULL && phdr->p_type == PT_NOTE)
fd33ee5
 	{
fd33ee5
 	  note_data = elf_getdata_rawchunk (core, phdr->p_offset,
fd33ee5
-					    phdr->p_filesz, ELF_T_NHDR);
fd33ee5
+					    phdr->p_filesz, (phdr->p_align == 8
fd33ee5
+							     ? ELF_T_NHDR8
fd33ee5
+							     : ELF_T_NHDR));
fd33ee5
 	  break;
fd33ee5
 	}
fd33ee5
     }
fd33ee5
diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c
fd33ee5
index 9d0fef2..360e4ee 100644
fd33ee5
--- a/libdwfl/linux-kernel-modules.c
fd33ee5
+++ b/libdwfl/linux-kernel-modules.c
fd33ee5
@@ -39,6 +39,7 @@
fd33ee5
 #include <config.h>
fd33ee5
 #include <system.h>
fd33ee5
 
fd33ee5
+#include "libelfP.h"
fd33ee5
 #include "libdwflP.h"
fd33ee5
 #include <inttypes.h>
fd33ee5
 #include <errno.h>
fd33ee5
@@ -554,15 +555,41 @@ check_notes (Dwfl_Module *mod, const char *notesfile,
fd33ee5
     return 1;
fd33ee5
 
fd33ee5
   unsigned char *p = buf.data;
fd33ee5
+  size_t len = 0;
fd33ee5
   while (p < &buf.data[n])
fd33ee5
     {
fd33ee5
       /* No translation required since we are reading the native kernel.  */
fd33ee5
       GElf_Nhdr *nhdr = (void *) p;
fd33ee5
-      p += sizeof *nhdr;
fd33ee5
+      len += sizeof *nhdr;
fd33ee5
+      p += len;
fd33ee5
       unsigned char *name = p;
fd33ee5
-      p += (nhdr->n_namesz + 3) & -4U;
fd33ee5
-      unsigned char *bits = p;
fd33ee5
-      p += (nhdr->n_descsz + 3) & -4U;
fd33ee5
+      unsigned char *bits;
fd33ee5
+      /* This is somewhat ugly, GNU Property notes use different padding,
fd33ee5
+	 but all we have is the file content, so we have to actually check
fd33ee5
+	 the name and type.  */
fd33ee5
+      if (nhdr->n_type == NT_GNU_PROPERTY_TYPE_0
fd33ee5
+          && nhdr->n_namesz == sizeof "GNU"
fd33ee5
+          && name + nhdr->n_namesz < &buf.data[n]
fd33ee5
+          && !memcmp (name, "GNU", sizeof "GNU"))
fd33ee5
+	{
fd33ee5
+	  len += nhdr->n_namesz;
fd33ee5
+	  len = NOTE_ALIGN8 (len);
fd33ee5
+	  p = buf.data + len;
fd33ee5
+	  bits = p;
fd33ee5
+	  len += nhdr->n_descsz;
fd33ee5
+	  len = NOTE_ALIGN8 (len);
fd33ee5
+	  p = buf.data + len;
fd33ee5
+	}
fd33ee5
+      else
fd33ee5
+	{
fd33ee5
+	  len += nhdr->n_namesz;
fd33ee5
+	  len = NOTE_ALIGN4 (len);
fd33ee5
+	  p = buf.data + len;
fd33ee5
+	  bits = p;
fd33ee5
+	  len += nhdr->n_descsz;
fd33ee5
+	  len = NOTE_ALIGN4 (len);
fd33ee5
+	  p = buf.data + len;
fd33ee5
+	}
fd33ee5
 
fd33ee5
       if (p <= &buf.data[n]
fd33ee5
 	  && nhdr->n_type == NT_GNU_BUILD_ID
fd33ee5
diff --git a/libebl/eblobjnote.c b/libebl/eblobjnote.c
fd33ee5
index ca4f155..57e9f52 100644
fd33ee5
--- a/libebl/eblobjnote.c
fd33ee5
+++ b/libebl/eblobjnote.c
fd33ee5
@@ -1,5 +1,5 @@
fd33ee5
 /* Print contents of object file note.
fd33ee5
-   Copyright (C) 2002, 2007, 2009, 2011, 2015, 2016 Red Hat, Inc.
fd33ee5
+   Copyright (C) 2002, 2007, 2009, 2011, 2015, 2016, 2018 Red Hat, Inc.
fd33ee5
    This file is part of elfutils.
fd33ee5
    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
fd33ee5
 
fd33ee5
@@ -37,6 +37,8 @@
fd33ee5
 #include <string.h>
fd33ee5
 #include <libeblP.h>
fd33ee5
 
fd33ee5
+#include "libelfP.h"
fd33ee5
+
fd33ee5
 
fd33ee5
 void
fd33ee5
 ebl_object_note (Ebl *ebl, const char *name, uint32_t type,
fd33ee5
@@ -153,6 +155,187 @@ ebl_object_note (Ebl *ebl, const char *name, uint32_t type,
fd33ee5
 		    (int) descsz, desc);
fd33ee5
 	  break;
fd33ee5
 
fd33ee5
+	case NT_GNU_PROPERTY_TYPE_0:
fd33ee5
+	  if (strcmp (name, "GNU") == 0 && descsz > 0)
fd33ee5
+	    {
fd33ee5
+	      /* There are at least 2 words. type and datasz.  */
fd33ee5
+	      while (descsz >= 8)
fd33ee5
+		{
fd33ee5
+		  struct pr_prop
fd33ee5
+		  {
fd33ee5
+		    GElf_Word pr_type;
fd33ee5
+		    GElf_Word pr_datasz;
fd33ee5
+		  } prop;
fd33ee5
+
fd33ee5
+		  Elf_Data in =
fd33ee5
+		    {
fd33ee5
+		      .d_version = EV_CURRENT,
fd33ee5
+		      .d_type = ELF_T_WORD,
fd33ee5
+		      .d_size = 8,
fd33ee5
+		      .d_buf = (void *) desc
fd33ee5
+		    };
fd33ee5
+		  Elf_Data out =
fd33ee5
+		    {
fd33ee5
+		      .d_version = EV_CURRENT,
fd33ee5
+		      .d_type = ELF_T_WORD,
fd33ee5
+		      .d_size = descsz,
fd33ee5
+		      .d_buf = (void *) &prop
fd33ee5
+		    };
fd33ee5
+
fd33ee5
+		  if (gelf_xlatetom (ebl->elf, &out, &in,
fd33ee5
+				     elf_getident (ebl->elf,
fd33ee5
+						   NULL)[EI_DATA]) == NULL)
fd33ee5
+		    {
fd33ee5
+		      printf ("%s\n", elf_errmsg (-1));
fd33ee5
+		      return;
fd33ee5
+		    }
fd33ee5
+
fd33ee5
+		  desc += 8;
fd33ee5
+		  descsz -= 8;
fd33ee5
+
fd33ee5
+		  int elfclass = gelf_getclass (ebl->elf);
fd33ee5
+		  char *elfident = elf_getident (ebl->elf, NULL);
fd33ee5
+		  GElf_Ehdr ehdr;
fd33ee5
+		  gelf_getehdr (ebl->elf, &ehdr);
fd33ee5
+
fd33ee5
+		  /* Prefix.  */
fd33ee5
+		  printf ("    ");
fd33ee5
+		  if (prop.pr_type == GNU_PROPERTY_STACK_SIZE)
fd33ee5
+		    {
fd33ee5
+		      printf ("STACK_SIZE ");
fd33ee5
+		      if (prop.pr_datasz == 4 || prop.pr_datasz == 8)
fd33ee5
+			{
fd33ee5
+			  GElf_Addr addr;
fd33ee5
+			  in.d_type = ELF_T_ADDR;
fd33ee5
+			  out.d_type = ELF_T_ADDR;
fd33ee5
+			  in.d_size = prop.pr_datasz;
fd33ee5
+			  out.d_size = sizeof (addr);
fd33ee5
+			  in.d_buf = (void *) desc;
fd33ee5
+			  out.d_buf = (void *) &addr;
fd33ee5
+
fd33ee5
+			  if (gelf_xlatetom (ebl->elf, &out, &in,
fd33ee5
+					     elfident[EI_DATA]) == NULL)
fd33ee5
+			    {
fd33ee5
+			      printf ("%s\n", elf_errmsg (-1));
fd33ee5
+			      return;
fd33ee5
+			    }
fd33ee5
+			  printf ("%#" PRIx64 "\n", addr);
fd33ee5
+			}
fd33ee5
+		      else
fd33ee5
+			printf (" (garbage datasz: %" PRIx32 ")\n",
fd33ee5
+				prop.pr_datasz);
fd33ee5
+		    }
fd33ee5
+		  else if (prop.pr_type == GNU_PROPERTY_NO_COPY_ON_PROTECTED)
fd33ee5
+		    {
fd33ee5
+		      printf ("NO_COPY_ON_PROTECTION");
fd33ee5
+		      if (prop.pr_datasz == 0)
fd33ee5
+			printf ("\n");
fd33ee5
+		      else
fd33ee5
+			printf (" (garbage datasz: %" PRIx32 ")\n",
fd33ee5
+				prop.pr_datasz);
fd33ee5
+		    }
fd33ee5
+		  else if (prop.pr_type >= GNU_PROPERTY_LOPROC
fd33ee5
+		      && prop.pr_type <= GNU_PROPERTY_HIPROC
fd33ee5
+		      && (ehdr.e_machine == EM_386
fd33ee5
+			  || ehdr.e_machine == EM_X86_64))
fd33ee5
+		    {
fd33ee5
+		      printf ("X86 ");
fd33ee5
+		      if (prop.pr_type == GNU_PROPERTY_X86_FEATURE_1_AND)
fd33ee5
+			{
fd33ee5
+			  printf ("FEATURE_1_AND: ");
fd33ee5
+
fd33ee5
+			  if (prop.pr_datasz == 4)
fd33ee5
+			    {
fd33ee5
+			      GElf_Word data;
fd33ee5
+			      in.d_type = ELF_T_WORD;
fd33ee5
+			      out.d_type = ELF_T_WORD;
fd33ee5
+			      in.d_size = 4;
fd33ee5
+			      out.d_size = 4;
fd33ee5
+			      in.d_buf = (void *) desc;
fd33ee5
+			      out.d_buf = (void *) &dat;;
fd33ee5
+
fd33ee5
+			      if (gelf_xlatetom (ebl->elf, &out, &in,
fd33ee5
+						 elfident[EI_DATA]) == NULL)
fd33ee5
+				{
fd33ee5
+				  printf ("%s\n", elf_errmsg (-1));
fd33ee5
+				  return;
fd33ee5
+				}
fd33ee5
+			      printf ("%08" PRIx32 " ", data);
fd33ee5
+
fd33ee5
+			      if ((data & GNU_PROPERTY_X86_FEATURE_1_IBT)
fd33ee5
+				  != 0)
fd33ee5
+				{
fd33ee5
+				  printf ("IBT");
fd33ee5
+				  data &= ~GNU_PROPERTY_X86_FEATURE_1_IBT;
fd33ee5
+				  if (data != 0)
fd33ee5
+				    printf (" ");
fd33ee5
+				}
fd33ee5
+
fd33ee5
+			      if ((data & GNU_PROPERTY_X86_FEATURE_1_SHSTK)
fd33ee5
+				  != 0)
fd33ee5
+				{
fd33ee5
+				  printf ("SHSTK");
fd33ee5
+				  data &= ~GNU_PROPERTY_X86_FEATURE_1_SHSTK;
fd33ee5
+				  if (data != 0)
fd33ee5
+				    printf (" ");
fd33ee5
+				}
fd33ee5
+
fd33ee5
+			      if (data != 0)
fd33ee5
+				printf ("UNKNOWN");
fd33ee5
+			    }
fd33ee5
+			  else
fd33ee5
+			    printf ("<bad datasz: %" PRId32 ">",
fd33ee5
+				    prop.pr_datasz);
fd33ee5
+
fd33ee5
+			  printf ("\n");
fd33ee5
+			}
fd33ee5
+		      else
fd33ee5
+			{
fd33ee5
+			  printf ("%#" PRIx32, prop.pr_type);
fd33ee5
+			  if (prop.pr_datasz > 0)
fd33ee5
+			    {
fd33ee5
+			      printf (" data: ");
fd33ee5
+			      size_t i;
fd33ee5
+			      for (i = 0; i < prop.pr_datasz - 1; i++)
fd33ee5
+				printf ("%02" PRIx8 " ", (uint8_t) desc[i]);
fd33ee5
+			      printf ("%02" PRIx8 "\n", (uint8_t) desc[i]);
fd33ee5
+			    }
fd33ee5
+			}
fd33ee5
+		    }
fd33ee5
+		  else
fd33ee5
+		    {
fd33ee5
+		      if (prop.pr_type >= GNU_PROPERTY_LOPROC
fd33ee5
+			  && prop.pr_type <= GNU_PROPERTY_HIPROC)
fd33ee5
+			printf ("proc_type %#" PRIx32, prop.pr_type);
fd33ee5
+		      else if (prop.pr_type >= GNU_PROPERTY_LOUSER
fd33ee5
+			  && prop.pr_type <= GNU_PROPERTY_HIUSER)
fd33ee5
+			printf ("app_type %#" PRIx32, prop.pr_type);
fd33ee5
+		      else
fd33ee5
+			printf ("unknown_type %#" PRIx32, prop.pr_type);
fd33ee5
+
fd33ee5
+		      if (prop.pr_datasz > 0)
fd33ee5
+			{
fd33ee5
+			  printf (" data: ");
fd33ee5
+			  size_t i;
fd33ee5
+			  for (i = 0; i < prop.pr_datasz - 1; i++)
fd33ee5
+			    printf ("%02" PRIx8 " ", (uint8_t) desc[i]);
fd33ee5
+			  printf ("%02" PRIx8 "\n", (uint8_t) desc[i]);
fd33ee5
+			}
fd33ee5
+		    }
fd33ee5
+		  if (elfclass == ELFCLASS32)
fd33ee5
+		    {
fd33ee5
+		      desc += NOTE_ALIGN4 (prop.pr_datasz);
fd33ee5
+		      descsz -= NOTE_ALIGN4 (prop.pr_datasz);
fd33ee5
+		    }
fd33ee5
+		  else
fd33ee5
+		    {
fd33ee5
+		      desc += NOTE_ALIGN8 (prop.pr_datasz);
fd33ee5
+		      descsz -= NOTE_ALIGN8 (prop.pr_datasz);
fd33ee5
+		    }
fd33ee5
+		}
fd33ee5
+	    }
fd33ee5
+	  break;
fd33ee5
+
fd33ee5
 	case NT_GNU_ABI_TAG:
fd33ee5
 	  if (strcmp (name, "GNU") == 0 && descsz >= 8 && descsz % 4 == 0)
fd33ee5
 	    {
fd33ee5
diff --git a/libebl/eblobjnotetypename.c b/libebl/eblobjnotetypename.c
fd33ee5
index db040d2..af23cae 100644
fd33ee5
--- a/libebl/eblobjnotetypename.c
fd33ee5
+++ b/libebl/eblobjnotetypename.c
fd33ee5
@@ -91,6 +91,7 @@ ebl_object_note_type_name (Ebl *ebl, const char *name, uint32_t type,
fd33ee5
 	  KNOWNSTYPE (GNU_HWCAP),
fd33ee5
 	  KNOWNSTYPE (GNU_BUILD_ID),
fd33ee5
 	  KNOWNSTYPE (GNU_GOLD_VERSION),
fd33ee5
+	  KNOWNSTYPE (GNU_PROPERTY_TYPE_0),
fd33ee5
 	};
fd33ee5
 
fd33ee5
       /* Handle standard names.  */
fd33ee5
diff --git a/libelf/elf32_xlatetom.c b/libelf/elf32_xlatetom.c
fd33ee5
index 13cd485..3b94cac 100644
fd33ee5
--- a/libelf/elf32_xlatetom.c
fd33ee5
+++ b/libelf/elf32_xlatetom.c
fd33ee5
@@ -60,7 +60,7 @@ elfw2(LIBELFBITS, xlatetom) (Elf_Data *dest, const Elf_Data *src,
fd33ee5
   /* We shouldn't require integer number of records when processing
fd33ee5
      notes.  Payload bytes follow the header immediately, it's not an
fd33ee5
      array of records as is the case otherwise.  */
fd33ee5
-  if (src->d_type != ELF_T_NHDR
fd33ee5
+  if (src->d_type != ELF_T_NHDR && src->d_type != ELF_T_NHDR8
fd33ee5
       && src->d_size % recsize != 0)
fd33ee5
     {
fd33ee5
       __libelf_seterrno (ELF_E_INVALID_DATA);
fd33ee5
diff --git a/libelf/elf_compress.c b/libelf/elf_compress.c
fd33ee5
index 711be59..fd412e8 100644
fd33ee5
--- a/libelf/elf_compress.c
fd33ee5
+++ b/libelf/elf_compress.c
fd33ee5
@@ -513,7 +513,8 @@ elf_compress (Elf_Scn *scn, int type, unsigned int flags)
fd33ee5
 
fd33ee5
       __libelf_reset_rawdata (scn, scn->zdata_base,
fd33ee5
 			      scn->zdata_size, scn->zdata_align,
fd33ee5
-			      __libelf_data_type (elf, sh_type));
fd33ee5
+			      __libelf_data_type (elf, sh_type,
fd33ee5
+						  scn->zdata_align));
fd33ee5
 
fd33ee5
       return 1;
fd33ee5
     }
fd33ee5
diff --git a/libelf/elf_compress_gnu.c b/libelf/elf_compress_gnu.c
fd33ee5
index dfa7c57..198dc7d 100644
fd33ee5
--- a/libelf/elf_compress_gnu.c
fd33ee5
+++ b/libelf/elf_compress_gnu.c
fd33ee5
@@ -196,7 +196,7 @@ elf_compress_gnu (Elf_Scn *scn, int inflate, unsigned int flags)
fd33ee5
 	}
fd33ee5
 
fd33ee5
       __libelf_reset_rawdata (scn, buf_out, size, sh_addralign,
fd33ee5
-			      __libelf_data_type (elf, sh_type));
fd33ee5
+			      __libelf_data_type (elf, sh_type, sh_addralign));
fd33ee5
 
fd33ee5
       scn->zdata_base = buf_out;
fd33ee5
 
fd33ee5
diff --git a/libelf/elf_getdata.c b/libelf/elf_getdata.c
fd33ee5
index 278dfa8..4f80aaf 100644
fd33ee5
--- a/libelf/elf_getdata.c
fd33ee5
+++ b/libelf/elf_getdata.c
fd33ee5
@@ -65,7 +65,7 @@ static const Elf_Type shtype_map[EV_NUM - 1][TYPEIDX (SHT_HISUNW) + 1] =
fd33ee5
       [SHT_PREINIT_ARRAY] = ELF_T_ADDR,
fd33ee5
       [SHT_GROUP] = ELF_T_WORD,
fd33ee5
       [SHT_SYMTAB_SHNDX] = ELF_T_WORD,
fd33ee5
-      [SHT_NOTE] = ELF_T_NHDR,
fd33ee5
+      [SHT_NOTE] = ELF_T_NHDR, /* Need alignment to guess ELF_T_NHDR8.  */
fd33ee5
       [TYPEIDX (SHT_GNU_verdef)] = ELF_T_VDEF,
fd33ee5
       [TYPEIDX (SHT_GNU_verneed)] = ELF_T_VNEED,
fd33ee5
       [TYPEIDX (SHT_GNU_versym)] = ELF_T_HALF,
fd33ee5
@@ -106,6 +106,7 @@ const uint_fast8_t __libelf_type_aligns[EV_NUM - 1][ELFCLASSNUM - 1][ELF_T_NUM]
fd33ee5
       [ELF_T_GNUHASH] = __alignof__ (Elf32_Word),			      \
fd33ee5
       [ELF_T_AUXV] = __alignof__ (ElfW2(Bits,auxv_t)),			      \
fd33ee5
       [ELF_T_CHDR] = __alignof__ (ElfW2(Bits,Chdr)),			      \
fd33ee5
+      [ELF_T_NHDR8] = 8 /* Special case for GNU Property note.  */	      \
fd33ee5
     }
fd33ee5
     [EV_CURRENT - 1] =
fd33ee5
     {
fd33ee5
@@ -118,7 +119,7 @@ const uint_fast8_t __libelf_type_aligns[EV_NUM - 1][ELFCLASSNUM - 1][ELF_T_NUM]
fd33ee5
 
fd33ee5
 Elf_Type
fd33ee5
 internal_function
fd33ee5
-__libelf_data_type (Elf *elf, int sh_type)
fd33ee5
+__libelf_data_type (Elf *elf, int sh_type, GElf_Xword align)
fd33ee5
 {
fd33ee5
   /* Some broken ELF ABI for 64-bit machines use the wrong hash table
fd33ee5
      entry size.  See elf-knowledge.h for more information.  */
fd33ee5
@@ -129,7 +130,13 @@ __libelf_data_type (Elf *elf, int sh_type)
fd33ee5
       return (SH_ENTSIZE_HASH (ehdr) == 4 ? ELF_T_WORD : ELF_T_XWORD);
fd33ee5
     }
fd33ee5
   else
fd33ee5
-    return shtype_map[LIBELF_EV_IDX][TYPEIDX (sh_type)];
fd33ee5
+    {
fd33ee5
+      Elf_Type t = shtype_map[LIBELF_EV_IDX][TYPEIDX (sh_type)];
fd33ee5
+      /* Special case for GNU Property notes.  */
fd33ee5
+      if (t == ELF_T_NHDR && align == 8)
fd33ee5
+	t = ELF_T_NHDR8;
fd33ee5
+      return t;
fd33ee5
+    }
fd33ee5
 }
fd33ee5
 
fd33ee5
 /* Convert the data in the current section.  */
fd33ee5
@@ -272,7 +279,9 @@ __libelf_set_rawdata_wrlock (Elf_Scn *scn)
fd33ee5
       else
fd33ee5
 	{
fd33ee5
 	  Elf_Type t = shtype_map[LIBELF_EV_IDX][TYPEIDX (type)];
fd33ee5
-	  if (t == ELF_T_VDEF || t == ELF_T_NHDR
fd33ee5
+	  if (t == ELF_T_NHDR && align == 8)
fd33ee5
+	    t = ELF_T_NHDR8;
fd33ee5
+	  if (t == ELF_T_VDEF || t == ELF_T_NHDR || t == ELF_T_NHDR8
fd33ee5
 	      || (t == ELF_T_GNUHASH && elf->class == ELFCLASS64))
fd33ee5
 	    entsize = 1;
fd33ee5
 	  else
fd33ee5
@@ -357,7 +366,7 @@ __libelf_set_rawdata_wrlock (Elf_Scn *scn)
fd33ee5
   if ((flags & SHF_COMPRESSED) != 0)
fd33ee5
     scn->rawdata.d.d_type = ELF_T_CHDR;
fd33ee5
   else
fd33ee5
-    scn->rawdata.d.d_type = __libelf_data_type (elf, type);
fd33ee5
+    scn->rawdata.d.d_type = __libelf_data_type (elf, type, align);
fd33ee5
   scn->rawdata.d.d_off = 0;
fd33ee5
 
fd33ee5
   /* Make sure the alignment makes sense.  d_align should be aligned both
fd33ee5
diff --git a/libelf/gelf_fsize.c b/libelf/gelf_fsize.c
fd33ee5
index 0c50926..d04ec5d 100644
fd33ee5
--- a/libelf/gelf_fsize.c
fd33ee5
+++ b/libelf/gelf_fsize.c
fd33ee5
@@ -64,6 +64,8 @@ const size_t __libelf_type_sizes[EV_NUM - 1][ELFCLASSNUM - 1][ELF_T_NUM] =
fd33ee5
       [ELF_T_VNEED]	= sizeof (ElfW2(LIBELFBITS, Ext_Verneed)),	      \
fd33ee5
       [ELF_T_VNAUX]	= sizeof (ElfW2(LIBELFBITS, Ext_Vernaux)),	      \
fd33ee5
       [ELF_T_NHDR]	= sizeof (ElfW2(LIBELFBITS, Ext_Nhdr)),		      \
fd33ee5
+      /* Note the header size is the same, but padding is different.  */      \
fd33ee5
+      [ELF_T_NHDR8]	= sizeof (ElfW2(LIBELFBITS, Ext_Nhdr)),		      \
fd33ee5
       [ELF_T_SYMINFO]	= sizeof (ElfW2(LIBELFBITS, Ext_Syminfo)),	      \
fd33ee5
       [ELF_T_MOVE]	= sizeof (ElfW2(LIBELFBITS, Ext_Move)),		      \
fd33ee5
       [ELF_T_LIB]	= sizeof (ElfW2(LIBELFBITS, Ext_Lib)),		      \
fd33ee5
diff --git a/libelf/gelf_getnote.c b/libelf/gelf_getnote.c
fd33ee5
index c75edda..6d33b35 100644
fd33ee5
--- a/libelf/gelf_getnote.c
fd33ee5
+++ b/libelf/gelf_getnote.c
fd33ee5
@@ -1,5 +1,5 @@
fd33ee5
 /* Get note information at the supplied offset.
fd33ee5
-   Copyright (C) 2007, 2014, 2015 Red Hat, Inc.
fd33ee5
+   Copyright (C) 2007, 2014, 2015, 2018 Red Hat, Inc.
fd33ee5
    This file is part of elfutils.
fd33ee5
 
fd33ee5
    This file is free software; you can redistribute it and/or modify
fd33ee5
@@ -43,7 +43,7 @@ gelf_getnote (Elf_Data *data, size_t offset, GElf_Nhdr *result,
fd33ee5
   if (data == NULL)
fd33ee5
     return 0;
fd33ee5
 
fd33ee5
-  if (unlikely (data->d_type != ELF_T_NHDR))
fd33ee5
+  if (unlikely (data->d_type != ELF_T_NHDR && data->d_type != ELF_T_NHDR8))
fd33ee5
     {
fd33ee5
       __libelf_seterrno (ELF_E_INVALID_HANDLE);
fd33ee5
       return 0;
fd33ee5
@@ -69,27 +69,42 @@ gelf_getnote (Elf_Data *data, size_t offset, GElf_Nhdr *result,
fd33ee5
       const GElf_Nhdr *n = data->d_buf + offset;
fd33ee5
       offset += sizeof *n;
fd33ee5
 
fd33ee5
-      /* Include padding.  Check below for overflow.  */
fd33ee5
-      GElf_Word namesz = NOTE_ALIGN (n->n_namesz);
fd33ee5
-      GElf_Word descsz = NOTE_ALIGN (n->n_descsz);
fd33ee5
-
fd33ee5
-      if (unlikely (offset > data->d_size
fd33ee5
-		    || data->d_size - offset < namesz
fd33ee5
-		    || (namesz == 0 && n->n_namesz != 0)))
fd33ee5
+      if (offset > data->d_size)
fd33ee5
 	offset = 0;
fd33ee5
       else
fd33ee5
 	{
fd33ee5
+	  /* This is slightly tricky, offset is guaranteed to be 4
fd33ee5
+	     byte aligned, which is what we need for the name_offset.
fd33ee5
+	     And normally desc_offset is also 4 byte aligned, but not
fd33ee5
+	     for GNU Property notes, then it should be 8.  So align
fd33ee5
+	     the offset, after adding the namesz, and include padding
fd33ee5
+	     in descsz to get to the end.  */
fd33ee5
 	  *name_offset = offset;
fd33ee5
-	  offset += namesz;
fd33ee5
-	  if (unlikely (offset > data->d_size
fd33ee5
-			|| data->d_size - offset < descsz
fd33ee5
-			|| (descsz == 0 && n->n_descsz != 0)))
fd33ee5
+	  offset += n->n_namesz;
fd33ee5
+	  if (offset > data->d_size)
fd33ee5
 	    offset = 0;
fd33ee5
 	  else
fd33ee5
 	    {
fd33ee5
-	      *desc_offset = offset;
fd33ee5
-	      offset += descsz;
fd33ee5
-	      *result = *n;
fd33ee5
+	      /* Include padding.  Check below for overflow.  */
fd33ee5
+	      GElf_Word descsz = (data->d_type == ELF_T_NHDR8
fd33ee5
+				  ? NOTE_ALIGN8 (n->n_descsz)
fd33ee5
+				  : NOTE_ALIGN4 (n->n_descsz));
fd33ee5
+
fd33ee5
+	      if (data->d_type == ELF_T_NHDR8)
fd33ee5
+		offset = NOTE_ALIGN8 (offset);
fd33ee5
+	      else
fd33ee5
+		offset = NOTE_ALIGN4 (offset);
fd33ee5
+
fd33ee5
+	      if (unlikely (offset > data->d_size
fd33ee5
+			    || data->d_size - offset < descsz
fd33ee5
+			    || (descsz == 0 && n->n_descsz != 0)))
fd33ee5
+		offset = 0;
fd33ee5
+	      else
fd33ee5
+		{
fd33ee5
+		  *desc_offset = offset;
fd33ee5
+		  offset += descsz;
fd33ee5
+		  *result = *n;
fd33ee5
+		}
fd33ee5
 	    }
fd33ee5
 	}
fd33ee5
     }
fd33ee5
diff --git a/libelf/gelf_xlate.c b/libelf/gelf_xlate.c
fd33ee5
index 479f143..b5d6ef3 100644
fd33ee5
--- a/libelf/gelf_xlate.c
fd33ee5
+++ b/libelf/gelf_xlate.c
fd33ee5
@@ -195,7 +195,8 @@ const xfct_t __elf_xfctstom[EV_NUM - 1][EV_NUM - 1][ELFCLASSNUM - 1][ELF_T_NUM]
fd33ee5
 	[ELF_T_VDAUX]	= elf_cvt_Verdef,				      \
fd33ee5
 	[ELF_T_VNEED]	= elf_cvt_Verneed,				      \
fd33ee5
 	[ELF_T_VNAUX]	= elf_cvt_Verneed,				      \
fd33ee5
-	[ELF_T_NHDR]	= elf_cvt_note,					      \
fd33ee5
+	[ELF_T_NHDR]	= elf_cvt_note4,				      \
fd33ee5
+	[ELF_T_NHDR8]	= elf_cvt_note8,				      \
fd33ee5
 	[ELF_T_SYMINFO] = ElfW2(Bits, cvt_Syminfo),			      \
fd33ee5
 	[ELF_T_MOVE]	= ElfW2(Bits, cvt_Move),			      \
fd33ee5
 	[ELF_T_LIB]	= ElfW2(Bits, cvt_Lib),				      \
fd33ee5
diff --git a/libelf/libelf.h b/libelf/libelf.h
fd33ee5
index d11358c..1ff11c9 100644
fd33ee5
--- a/libelf/libelf.h
fd33ee5
+++ b/libelf/libelf.h
fd33ee5
@@ -117,6 +117,8 @@ typedef enum
fd33ee5
   ELF_T_GNUHASH,		/* GNU-style hash section.  */
fd33ee5
   ELF_T_AUXV,			/* Elf32_auxv_t, Elf64_auxv_t, ... */
fd33ee5
   ELF_T_CHDR,			/* Compressed, Elf32_Chdr, Elf64_Chdr, ... */
fd33ee5
+  ELF_T_NHDR8,			/* Special GNU Properties note.  Same as Nhdr,
fd33ee5
+				   except padding.  */
fd33ee5
   /* Keep this the last entry.  */
fd33ee5
   ELF_T_NUM
fd33ee5
 } Elf_Type;
fd33ee5
diff --git a/libelf/libelfP.h b/libelf/libelfP.h
fd33ee5
index ed216c8..fa6d55d 100644
fd33ee5
--- a/libelf/libelfP.h
fd33ee5
+++ b/libelf/libelfP.h
fd33ee5
@@ -452,7 +452,8 @@ extern const uint_fast8_t __libelf_type_aligns[EV_NUM - 1][ELFCLASSNUM - 1][ELF_
fd33ee5
 /* Given an Elf handle and a section type returns the Elf_Data d_type.
fd33ee5
    Should not be called when SHF_COMPRESSED is set, the d_type should
fd33ee5
    be ELF_T_BYTE.  */
fd33ee5
-extern Elf_Type __libelf_data_type (Elf *elf, int sh_type) internal_function;
fd33ee5
+extern Elf_Type __libelf_data_type (Elf *elf, int sh_type, GElf_Xword align)
fd33ee5
+  internal_function;
fd33ee5
 
fd33ee5
 /* The libelf API does not have such a function but it is still useful.
fd33ee5
    Get the memory size for the given type.
fd33ee5
@@ -624,8 +625,13 @@ extern void __libelf_reset_rawdata (Elf_Scn *scn, void *buf, size_t size,
fd33ee5
       }									      \
fd33ee5
   } while (0)
fd33ee5
 
fd33ee5
-/* Align offset to 4 bytes as needed for note name and descriptor data.  */
fd33ee5
-#define NOTE_ALIGN(n)	(((n) + 3) & -4U)
fd33ee5
+/* Align offset to 4 bytes as needed for note name and descriptor data.
fd33ee5
+   This is almost always used, except for GNU Property notes, which use
fd33ee5
+   8 byte padding...  */
fd33ee5
+#define NOTE_ALIGN4(n)	(((n) + 3) & -4U)
fd33ee5
+
fd33ee5
+/* Special note padding rule for GNU Property notes.  */
fd33ee5
+#define NOTE_ALIGN8(n)	(((n) + 7) & -8U)
fd33ee5
 
fd33ee5
 /* Convenience macro.  */
fd33ee5
 #define INVALID_NDX(ndx, type, data) \
fd33ee5
diff --git a/libelf/note_xlate.h b/libelf/note_xlate.h
fd33ee5
index 62c6f63..9bdc3e2 100644
fd33ee5
--- a/libelf/note_xlate.h
fd33ee5
+++ b/libelf/note_xlate.h
fd33ee5
@@ -1,5 +1,5 @@
fd33ee5
 /* Conversion functions for notes.
fd33ee5
-   Copyright (C) 2007, 2009, 2014 Red Hat, Inc.
fd33ee5
+   Copyright (C) 2007, 2009, 2014, 2018 Red Hat, Inc.
fd33ee5
    This file is part of elfutils.
fd33ee5
 
fd33ee5
    This file is free software; you can redistribute it and/or modify
fd33ee5
@@ -27,38 +27,60 @@
fd33ee5
    not, see <http://www.gnu.org/licenses/>.  */
fd33ee5
 
fd33ee5
 static void
fd33ee5
-elf_cvt_note (void *dest, const void *src, size_t len, int encode)
fd33ee5
+elf_cvt_note (void *dest, const void *src, size_t len, int encode,
fd33ee5
+	      bool nhdr8)
fd33ee5
 {
fd33ee5
+  /* Note that the header is always the same size, but the padding
fd33ee5
+     differs for GNU Property notes.  */
fd33ee5
   assert (sizeof (Elf32_Nhdr) == sizeof (Elf64_Nhdr));
fd33ee5
 
fd33ee5
   while (len >= sizeof (Elf32_Nhdr))
fd33ee5
     {
fd33ee5
+      /* Convert the header.  */
fd33ee5
       (1 ? Elf32_cvt_Nhdr : Elf64_cvt_Nhdr) (dest, src, sizeof (Elf32_Nhdr),
fd33ee5
 					     encode);
fd33ee5
       const Elf32_Nhdr *n = encode ? src : dest;
fd33ee5
-      Elf32_Word namesz = NOTE_ALIGN (n->n_namesz);
fd33ee5
-      Elf32_Word descsz = NOTE_ALIGN (n->n_descsz);
fd33ee5
 
fd33ee5
-      len -= sizeof *n;
fd33ee5
-      src += sizeof *n;
fd33ee5
-      dest += sizeof *n;
fd33ee5
+      size_t note_len = sizeof *n;
fd33ee5
 
fd33ee5
-      if (namesz > len)
fd33ee5
+      /* desc needs to be aligned.  */
fd33ee5
+      note_len += n->n_namesz;
fd33ee5
+      note_len = nhdr8 ? NOTE_ALIGN8 (note_len) : NOTE_ALIGN4 (note_len);
fd33ee5
+      if (note_len > len || note_len < 8)
fd33ee5
 	break;
fd33ee5
-      len -= namesz;
fd33ee5
-      if (descsz > len)
fd33ee5
+
fd33ee5
+      /* data as a whole needs to be aligned.  */
fd33ee5
+      note_len += n->n_descsz;
fd33ee5
+      note_len = nhdr8 ? NOTE_ALIGN8 (note_len) : NOTE_ALIGN4 (note_len);
fd33ee5
+      if (note_len > len || note_len < 8)
fd33ee5
 	break;
fd33ee5
-      len -= descsz;
fd33ee5
 
fd33ee5
+      /* Copy or skip the note data.  */
fd33ee5
+      size_t note_data_len = note_len - sizeof *n;
fd33ee5
+      src += sizeof *n;
fd33ee5
+      dest += sizeof *n;
fd33ee5
       if (src != dest)
fd33ee5
-	memcpy (dest, src, namesz + descsz);
fd33ee5
+	memcpy (dest, src, note_data_len);
fd33ee5
 
fd33ee5
-      src += namesz + descsz;
fd33ee5
-      dest += namesz + descsz;
fd33ee5
+      src += note_data_len;
fd33ee5
+      dest += note_data_len;
fd33ee5
+      len -= note_len;
fd33ee5
     }
fd33ee5
 
fd33ee5
-    /* Copy opver any leftover data unconcerted.  Probably part of
fd33ee5
+    /* Copy over any leftover data unconverted.  Probably part of
fd33ee5
        truncated name/desc data.  */
fd33ee5
     if (unlikely (len > 0) && src != dest)
fd33ee5
       memcpy (dest, src, len);
fd33ee5
 }
fd33ee5
+
fd33ee5
+static void
fd33ee5
+elf_cvt_note4 (void *dest, const void *src, size_t len, int encode)
fd33ee5
+{
fd33ee5
+  elf_cvt_note (dest, src, len, encode, false);
fd33ee5
+}
fd33ee5
+
fd33ee5
+static void
fd33ee5
+elf_cvt_note8 (void *dest, const void *src, size_t len, int encode)
fd33ee5
+{
fd33ee5
+  elf_cvt_note (dest, src, len, encode, true);
fd33ee5
+}
fd33ee5
diff --git a/src/elflint.c b/src/elflint.c
fd33ee5
index 3d44595..fa3af4c 100644
fd33ee5
--- a/src/elflint.c
fd33ee5
+++ b/src/elflint.c
fd33ee5
@@ -4331,6 +4331,7 @@ section [%2d] '%s': unknown core file note type %" PRIu32
fd33ee5
 	  case NT_GNU_HWCAP:
fd33ee5
 	  case NT_GNU_BUILD_ID:
fd33ee5
 	  case NT_GNU_GOLD_VERSION:
fd33ee5
+	  case NT_GNU_PROPERTY_TYPE_0:
fd33ee5
 	    break;
fd33ee5
 
fd33ee5
 	  case 0:
fd33ee5
@@ -4376,7 +4377,8 @@ phdr[%d]: no note entries defined for the type of file\n"),
fd33ee5
   GElf_Off notes_size = 0;
fd33ee5
   Elf_Data *data = elf_getdata_rawchunk (ebl->elf,
fd33ee5
 					 phdr->p_offset, phdr->p_filesz,
fd33ee5
-					 ELF_T_NHDR);
fd33ee5
+					 (phdr->p_align == 8
fd33ee5
+					  ? ELF_T_NHDR8 : ELF_T_NHDR));
fd33ee5
   if (data != NULL && data->d_buf != NULL)
fd33ee5
     notes_size = check_note_data (ebl, ehdr, data, 0, cnt, phdr->p_offset);
fd33ee5
 
fd33ee5
diff --git a/src/readelf.c b/src/readelf.c
fd33ee5
index 72ae04e..ccd07eb 100644
fd33ee5
--- a/src/readelf.c
fd33ee5
+++ b/src/readelf.c
fd33ee5
@@ -12300,7 +12300,8 @@ handle_notes (Ebl *ebl, GElf_Ehdr *ehdr)
fd33ee5
       handle_notes_data (ebl, ehdr, phdr->p_offset,
fd33ee5
 			 elf_getdata_rawchunk (ebl->elf,
fd33ee5
 					       phdr->p_offset, phdr->p_filesz,
fd33ee5
-					       ELF_T_NHDR));
fd33ee5
+					       (phdr->p_align == 8
fd33ee5
+						? ELF_T_NHDR8 : ELF_T_NHDR)));
fd33ee5
     }
fd33ee5
 }
fd33ee5