x86: Add GNU_PROPERTY_X86_UINT32_VALID
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 24 Aug 2018 11:37:45 +0000 (04:37 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 24 Aug 2018 11:38:02 +0000 (04:38 -0700)
The older linker treats .note.gnu.property section as a generic note
and just concatenates all .note.gnu.property sections from the input
to the output.  On CET-enabled OS, the output of the older linker is
marked as CET enabled, but in fact, it is not CET enabled and it crashes
on CET-enabled machines.

This patch defines GNU_PROPERTY_X86_UINT32_VALID.  Linker is updated to
set the GNU_PROPERTY_X86_UINT32_VALID bit in GNU property note for
non-relocatable output to differentiate outputs from the older linker.

bfd/

* elfxx-x86.c (_bfd_x86_elf_parse_gnu_properties): Mask out the
GNU_PROPERTY_X86_UINT32_VALID bit.
(_bfd_x86_elf_link_fixup_gnu_properties): Set the
GNU_PROPERTY_X86_UINT32_VALID bit for non-relocatable output.

binutils/

* readelf.c (print_gnu_property_note): Check the
GNU_PROPERTY_X86_UINT32_VALID bit for invalid GNU property note.

include/

* elf/common.h (GNU_PROPERTY_X86_UINT32_VALID): New.

bfd/ChangeLog
bfd/elfxx-x86.c
binutils/ChangeLog
binutils/readelf.c
include/ChangeLog
include/elf/common.h

index 1cadfc4b7f554aecf2b66e9298fbd335699a198a..44690b831f1973b3e0035c7d3bcea0ad288c9ab8 100644 (file)
@@ -1,3 +1,10 @@
+2018-08-24  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * elfxx-x86.c (_bfd_x86_elf_parse_gnu_properties): Mask out the
+       GNU_PROPERTY_X86_UINT32_VALID bit.
+       (_bfd_x86_elf_link_fixup_gnu_properties): Set the
+       GNU_PROPERTY_X86_UINT32_VALID bit for non-relocatable output.
+
 2018-08-23  Zenith423  <zenith432@users.sourceforge.net>
 
        PR 23460
index 1a4c723969f37c65706d3200eec9a32158844236..0d91e4dfc95968d2d06c0a3a8f8d7254e3ff9b38 100644 (file)
@@ -2378,8 +2378,10 @@ _bfd_x86_elf_parse_gnu_properties (bfd *abfd, unsigned int type,
          return property_corrupt;
        }
       prop = _bfd_elf_get_property (abfd, type, datasz);
-      /* Combine properties of the same type.  */
-      prop->u.number |= bfd_h_get_32 (abfd, ptr);
+      /* Mask out GNU_PROPERTY_X86_UINT32_VALID and combine properties
+        of the same type.  */
+      prop->u.number |= (bfd_h_get_32 (abfd, ptr)
+                        & ~GNU_PROPERTY_X86_UINT32_VALID);
       prop->pr_kind = property_number;
       break;
 
@@ -2963,9 +2965,8 @@ error_alignment:
 /* Fix up x86 GNU properties.  */
 
 void
-_bfd_x86_elf_link_fixup_gnu_properties
-  (struct bfd_link_info *info ATTRIBUTE_UNUSED,
-   elf_property_list **listp)
+_bfd_x86_elf_link_fixup_gnu_properties (struct bfd_link_info *info,
+                                       elf_property_list **listp)
 {
   elf_property_list *p;
 
@@ -2981,6 +2982,12 @@ _bfd_x86_elf_link_fixup_gnu_properties
            *listp = p->next;
            continue;
          }
+
+       /* Mark x86-specific properties with X86_UINT32_VALID for
+          non-relocatable output.  */
+       if (!(bfd_link_relocatable (info)))
+         p->property.u.number |= GNU_PROPERTY_X86_UINT32_VALID;
+
        listp = &p->next;
        break;
       default:
index 673bd904dc801d339a11bc6382f776ffe1598481..76af83b6ec574e09e220f29c20748b77802cf1ff 100644 (file)
@@ -1,3 +1,8 @@
+2018-08-24  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * readelf.c (print_gnu_property_note): Check the
+       GNU_PROPERTY_X86_UINT32_VALID bit for invalid GNU property note.
+
 2018-08-23  Alan Modra  <amodra@gmail.com>
 
        * readelf.c (get_ppc64_symbol_other): Return NULL if st_other
index 2d9d48d002b0a43785125e9ff61bbc450f839f9e..df946528cad20cb4f65ef74a877b4daabec8a9ee 100644 (file)
@@ -17067,30 +17067,56 @@ print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote)
              || filedata->file_header.e_machine == EM_IAMCU
              || filedata->file_header.e_machine == EM_386)
            {
+             unsigned int bitmask;
+
+             if (datasz == 4)
+               {
+                 bitmask = byte_get (ptr, 4);
+                 if (filedata->file_header.e_type == ET_EXEC
+                     || filedata->file_header.e_type == ET_DYN)
+                   {
+                     if ((bitmask & GNU_PROPERTY_X86_UINT32_VALID))
+                       bitmask &= ~GNU_PROPERTY_X86_UINT32_VALID;
+                     else
+                       printf ("Invalid ");
+                   }
+               }
+             else
+               bitmask = 0;
+
              switch (type)
                {
                case GNU_PROPERTY_X86_ISA_1_USED:
-                 printf ("x86 ISA used: ");
                  if (datasz != 4)
-                   printf (_("<corrupt length: %#x> "), datasz);
+                   printf (_("x86 ISA used: <corrupt length: %#x> "),
+                           datasz);
                  else
-                   decode_x86_isa (byte_get (ptr, 4));
+                   {
+                     printf ("x86 ISA used: ");
+                     decode_x86_isa (bitmask);
+                   }
                  goto next;
 
                case GNU_PROPERTY_X86_ISA_1_NEEDED:
-                 printf ("x86 ISA needed: ");
                  if (datasz != 4)
-                   printf (_("<corrupt length: %#x> "), datasz);
+                   printf (_("x86 ISA needed: <corrupt length: %#x> "),
+                           datasz);
                  else
-                   decode_x86_isa (byte_get (ptr, 4));
+                   {
+                     printf ("x86 ISA needed: ");
+                     decode_x86_isa (bitmask);
+                   }
                  goto next;
 
                case GNU_PROPERTY_X86_FEATURE_1_AND:
-                 printf ("x86 feature: ");
                  if (datasz != 4)
-                   printf (_("<corrupt length: %#x> "), datasz);
+                   printf (_("x86 feature: <corrupt length: %#x> "),
+                           datasz);
                  else
-                   decode_x86_feature (type, byte_get (ptr, 4));
+                   {
+                     printf ("x86 feature: ");
+                     decode_x86_feature (type, bitmask);
+                   }
                  goto next;
 
                default:
index 69cc57d75651ff299490d5811d76f46beee82e5b..4b933b157e7c946d3d96a9852a21debbddcc4887 100644 (file)
@@ -1,3 +1,7 @@
+2018-08-24  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * elf/common.h (GNU_PROPERTY_X86_UINT32_VALID): New.
+
 2018-08-21  John Darrington  <john@darrington.wattle.id.au>
 
        * elf/s12z.h: Rename R_S12Z_UKNWN_3 to R_S12Z_EXT18.
index 1a940ff7b52c779f07cf69032f33af46c404e1e9..55c5505bac9f09b7e2c58bf77350c1ece90e7023 100644 (file)
 #define GNU_PROPERTY_X86_ISA_1_NEEDED          0xc0000001
 #define GNU_PROPERTY_X86_FEATURE_1_AND         0xc0000002
 
+/* Set by linker to indicate that the property is valid.  */
+#define GNU_PROPERTY_X86_UINT32_VALID          (1U << 31)
+
 #define GNU_PROPERTY_X86_ISA_1_486           (1U << 0)
 #define GNU_PROPERTY_X86_ISA_1_586           (1U << 1)
 #define GNU_PROPERTY_X86_ISA_1_686           (1U << 2)
This page took 0.036942 seconds and 4 git commands to generate.