[PATCH 0/2] elf: Update GNU_PROPERTY_X86_XXX macros

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 0/2] elf: Update GNU_PROPERTY_X86_XXX macros

H.J. Lu-30
This set of patches updates GNU_PROPERTY_X86_XXX macros according to the
x86 program property in x86-64 psABI:

https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-property.pdf

The NT_GNU_PROPERTY_TYPE_0 note is used to describe features and
capabilities supported by ELF binaries.  Consumers of ELF binaries can
consult the NT_GNU_PROPERTY_TYPE_0 note to make appropriate decisions.
If a consumer of ELF binaries ignores NT_GNU_PROPERTY_TYPE_0 note, nothing
is changed.  The new GNU_PROPERTY_X86_UINT32_VALID bit is used by
_dl_process_cet_property_note to detect if the NT_GNU_PROPERTY_TYPE_0
note is generated by updated linkers so that it can stop checking for
invalid .note.gnu.property section.

H.J. Lu (2):
  elf: Update GNU_PROPERTY_X86_XXX macros [BZ #23797]
  x86/CET: Stop if the GNU_PROPERTY_X86_UINT32_VALID bit is set

 elf/elf.h             | 98 ++++++++++++++++++++++++++++++++-----------
 sysdeps/x86/dl-prop.h |  6 +++
 2 files changed, 79 insertions(+), 25 deletions(-)

--
2.19.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 1/2] elf: Update GNU_PROPERTY_X86_XXX macros [BZ #23797]

H.J. Lu-30
This patch updates GNU_PROPERTY_X86_XXX macros according to the x86
program property in x86-64 psABI:

https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-property.pdf

1. GNU_PROPERTY_X86_UINT32_AND_XXX: A 4-byte unsigned integer property.
A bit is set if it is set in all relocatable inputs:

 #define GNU_PROPERTY_X86_UINT32_AND_LO      0xc0000002
 #define GNU_PROPERTY_X86_UINT32_AND_HI      0xc0007fff

2. GNU_PROPERTY_X86_UINT32_OR_XXX: A 4-byte unsigned integer property.
A bit is set if it is set in any relocatable inputs:

 #define GNU_PROPERTY_X86_UINT32_OR_LO    0xc0008000
 #define GNU_PROPERTY_X86_UINT32_OR_HI    0xc000ffff

3. GNU_PROPERTY_X86_UINT32_OR_AND_XXX: A 4-byte unsigned integer property.
A bit is set if it is set in any relocatable inputs and the property is
present in all relocatable inputs:

 #define GNU_PROPERTY_X86_UINT32_OR_AND_LO   0xc0010000
 #define GNU_PROPERTY_X86_UINT32_OR_AND_HI   0xc0017fff

4. GNU_PROPERTY_X86_FEATURE_2_NEEDED, GNU_PROPERTY_X86_FEATURE_2_USED
and GNU_PROPERTY_X86_FEATURE_2_XXX bits.

GNU_PROPERTY_X86_FEATURE_1_AND is unchanged.  GNU_PROPERTY_X86_ISA_1_USED
and GNU_PROPERTY_X86_FEATURE_2_USED are redefined to better support
targeted processors since GNU_PROPERTY_X86_ISA_1_?86 aren't isn't very
useful.  A new set of GNU_PROPERTY_X86_ISA_1_XXX bits are defined.  The
previous GNU_PROPERTY_X86_ISA_1_XXX macros are removed.

NOTE: The NT_GNU_PROPERTY_TYPE_0 note is used to describe features and
capabilities supported by ELF binaries.  Consumers of ELF binaries can
consult the NT_GNU_PROPERTY_TYPE_0 note to make appropriate decisions.
If a consumer of ELF binaries ignores NT_GNU_PROPERTY_TYPE_0 note, nothing
is changed.

        [BZ #23797]
        * elf.h (GNU_PROPERTY_X86_UINT32_AND_LO): New.
        (GNU_PROPERTY_X86_UINT32_AND_HI): Likewise.
        (GNU_PROPERTY_X86_UINT32_OR_LO): Likewise.
        (GNU_PROPERTY_X86_UINT32_OR_HI): Likewise.
        (GNU_PROPERTY_X86_UINT32_OR_AND_LO): Likewise.
        (GNU_PROPERTY_X86_UINT32_OR_AND_HI): Likewise.
        (GNU_PROPERTY_X86_ISA_1_CMOV): Likewise.
        (GNU_PROPERTY_X86_ISA_1_SSE): Likewise.
        (GNU_PROPERTY_X86_ISA_1_SSE2): Likewise.
        (GNU_PROPERTY_X86_ISA_1_SSE3): Likewise.
        (GNU_PROPERTY_X86_ISA_1_SSSE3): Likewise.
        (GNU_PROPERTY_X86_ISA_1_SSE4_1): Likewise.
        (GNU_PROPERTY_X86_ISA_1_SSE4_2): Likewise.
        (GNU_PROPERTY_X86_ISA_1_AVX): Likewise.
        (GNU_PROPERTY_X86_ISA_1_AVX2): Likewise.
        (GNU_PROPERTY_X86_ISA_1_FMA): Likewise.
        (GNU_PROPERTY_X86_ISA_1_AVX512F): Likewise.
        (GNU_PROPERTY_X86_ISA_1_AVX512CD): Likewise.
        (GNU_PROPERTY_X86_ISA_1_AVX512ER): Likewise.
        (GNU_PROPERTY_X86_ISA_1_AVX512PF): Likewise.
        (GNU_PROPERTY_X86_ISA_1_AVX512VL): Likewise.
        (GNU_PROPERTY_X86_ISA_1_AVX512DQ): Likewise.
        (GNU_PROPERTY_X86_ISA_1_AVX512BW): Likewise.
        (GNU_PROPERTY_X86_ISA_1_AVX512_4FMAPS): Likewise.
        (GNU_PROPERTY_X86_ISA_1_AVX512_4VNNIW): Likewise.
        (GNU_PROPERTY_X86_ISA_1_AVX512_BITALG): Likewise.
        (GNU_PROPERTY_X86_ISA_1_AVX512_IFMA): Likewise.
        (GNU_PROPERTY_X86_ISA_1_AVX512_VBMI): Likewise.
        (GNU_PROPERTY_X86_ISA_1_AVX512_VBMI2): Likewise.
        (GNU_PROPERTY_X86_ISA_1_AVX512_VNNI): Likewise.
        (GNU_PROPERTY_X86_FEATURE_2_X86): Likewise.
        (GNU_PROPERTY_X86_FEATURE_2_X87): Likewise.
        (GNU_PROPERTY_X86_FEATURE_2_MMX): Likewise.
        (GNU_PROPERTY_X86_FEATURE_2_XMM): Likewise.
        (GNU_PROPERTY_X86_FEATURE_2_YMM): Likewise.
        (GNU_PROPERTY_X86_FEATURE_2_ZMM): Likewise.
        (GNU_PROPERTY_X86_FEATURE_2_FXSR): Likewise.
        (GNU_PROPERTY_X86_FEATURE_2_XSAVE): Likewise.
        (GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT): Likewise.
        (GNU_PROPERTY_X86_FEATURE_2_XSAVEC): Likewise.
        (GNU_PROPERTY_X86_FEATURE_1_AND): Updated to
        (GNU_PROPERTY_X86_UINT32_AND_LO + 0).
        (GNU_PROPERTY_X86_ISA_1_NEEDED): Defined to
        (GNU_PROPERTY_X86_UINT32_OR_LO + 0).
        (GNU_PROPERTY_X86_FEATURE_2_NEEDED): New.  Defined to
        (GNU_PROPERTY_X86_UINT32_OR_LO + 1).
        (GNU_PROPERTY_X86_ISA_1_USED): Defined to
        (GNU_PROPERTY_X86_UINT32_OR_AND_LO + 0).
        (GNU_PROPERTY_X86_FEATURE_2_USED): New.  Defined to
        (GNU_PROPERTY_X86_UINT32_OR_AND_LO + 1).
---
 elf/elf.h | 98 +++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 73 insertions(+), 25 deletions(-)

diff --git a/elf/elf.h b/elf/elf.h
index 69ffa2ec0e..b4bd428187 100644
--- a/elf/elf.h
+++ b/elf/elf.h
@@ -1307,33 +1307,81 @@ typedef struct
 /* Application-specific semantics, hi */
 #define GNU_PROPERTY_HIUSER 0xffffffff
 
-/* The x86 instruction sets indicated by the corresponding bits are
-   used in program.  Their support in the hardware is optional.  */
-#define GNU_PROPERTY_X86_ISA_1_USED 0xc0000000
+/* A 4-byte unsigned integer property: A bit is set if it is set in all
+   relocatable inputs.  */
+#define GNU_PROPERTY_X86_UINT32_AND_LO 0xc0000002
+#define GNU_PROPERTY_X86_UINT32_AND_HI 0xc0007fff
+
+/* A 4-byte unsigned integer property: A bit is set if it is set in any
+   relocatable inputs.  */
+#define GNU_PROPERTY_X86_UINT32_OR_LO 0xc0008000
+#define GNU_PROPERTY_X86_UINT32_OR_HI 0xc000ffff
+
+/* A 4-byte unsigned integer property: A bit is set if it is set in any
+   relocatable inputs and the property is present in all relocatable
+   inputs.  */
+#define GNU_PROPERTY_X86_UINT32_OR_AND_LO 0xc0010000
+#define GNU_PROPERTY_X86_UINT32_OR_AND_HI 0xc0017fff
+
+/* X86 processor-specific features used in program.  */
+#define GNU_PROPERTY_X86_FEATURE_1_AND \
+  (GNU_PROPERTY_X86_UINT32_AND_LO + 0)
+
 /* The x86 instruction sets indicated by the corresponding bits are
    used in program and they must be supported by the hardware.   */
-#define GNU_PROPERTY_X86_ISA_1_NEEDED 0xc0000001
-/* X86 processor-specific features used in program.  */
-#define GNU_PROPERTY_X86_FEATURE_1_AND 0xc0000002
-
-#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)
-#define GNU_PROPERTY_X86_ISA_1_SSE (1U << 3)
-#define GNU_PROPERTY_X86_ISA_1_SSE2 (1U << 4)
-#define GNU_PROPERTY_X86_ISA_1_SSE3 (1U << 5)
-#define GNU_PROPERTY_X86_ISA_1_SSSE3 (1U << 6)
-#define GNU_PROPERTY_X86_ISA_1_SSE4_1 (1U << 7)
-#define GNU_PROPERTY_X86_ISA_1_SSE4_2 (1U << 8)
-#define GNU_PROPERTY_X86_ISA_1_AVX (1U << 9)
-#define GNU_PROPERTY_X86_ISA_1_AVX2 (1U << 10)
-#define GNU_PROPERTY_X86_ISA_1_AVX512F (1U << 11)
-#define GNU_PROPERTY_X86_ISA_1_AVX512CD (1U << 12)
-#define GNU_PROPERTY_X86_ISA_1_AVX512ER (1U << 13)
-#define GNU_PROPERTY_X86_ISA_1_AVX512PF (1U << 14)
-#define GNU_PROPERTY_X86_ISA_1_AVX512VL (1U << 15)
-#define GNU_PROPERTY_X86_ISA_1_AVX512DQ (1U << 16)
-#define GNU_PROPERTY_X86_ISA_1_AVX512BW (1U << 17)
+#define GNU_PROPERTY_X86_ISA_1_NEEDED \
+  (GNU_PROPERTY_X86_UINT32_OR_LO + 0)
+#define GNU_PROPERTY_X86_FEATURE_2_NEEDED \
+  (GNU_PROPERTY_X86_UINT32_OR_LO + 1)
+
+/* The x86 instruction sets indicated by the corresponding bits are
+   used in program.  Their support in the hardware is optional.  */
+#define GNU_PROPERTY_X86_ISA_1_USED \
+  (GNU_PROPERTY_X86_UINT32_OR_AND_LO + 0)
+#define GNU_PROPERTY_X86_FEATURE_2_USED \
+  (GNU_PROPERTY_X86_UINT32_OR_AND_LO + 1)
+
+/* Set by linker to indicate that the property is valid.  */
+#define GNU_PROPERTY_X86_UINT32_VALID (1U << 31)
+
+#define GNU_PROPERTY_X86_FEATURE_1_IBT (1U << 0)
+#define GNU_PROPERTY_X86_FEATURE_1_SHSTK (1U << 1)
+
+#define GNU_PROPERTY_X86_ISA_1_CMOV (1U << 0)
+#define GNU_PROPERTY_X86_ISA_1_SSE (1U << 1)
+#define GNU_PROPERTY_X86_ISA_1_SSE2 (1U << 2)
+#define GNU_PROPERTY_X86_ISA_1_SSE3 (1U << 3)
+#define GNU_PROPERTY_X86_ISA_1_SSSE3 (1U << 4)
+#define GNU_PROPERTY_X86_ISA_1_SSE4_1 (1U << 5)
+#define GNU_PROPERTY_X86_ISA_1_SSE4_2 (1U << 6)
+#define GNU_PROPERTY_X86_ISA_1_AVX (1U << 7)
+#define GNU_PROPERTY_X86_ISA_1_AVX2 (1U << 8)
+#define GNU_PROPERTY_X86_ISA_1_FMA (1U << 9)
+#define GNU_PROPERTY_X86_ISA_1_AVX512F (1U << 10)
+#define GNU_PROPERTY_X86_ISA_1_AVX512CD (1U << 11)
+#define GNU_PROPERTY_X86_ISA_1_AVX512ER (1U << 12)
+#define GNU_PROPERTY_X86_ISA_1_AVX512PF (1U << 13)
+#define GNU_PROPERTY_X86_ISA_1_AVX512VL (1U << 14)
+#define GNU_PROPERTY_X86_ISA_1_AVX512DQ (1U << 15)
+#define GNU_PROPERTY_X86_ISA_1_AVX512BW (1U << 16)
+#define GNU_PROPERTY_X86_ISA_1_AVX512_4FMAPS (1U << 17)
+#define GNU_PROPERTY_X86_ISA_1_AVX512_4VNNIW (1U << 18)
+#define GNU_PROPERTY_X86_ISA_1_AVX512_BITALG (1U << 19)
+#define GNU_PROPERTY_X86_ISA_1_AVX512_IFMA (1U << 20)
+#define GNU_PROPERTY_X86_ISA_1_AVX512_VBMI (1U << 21)
+#define GNU_PROPERTY_X86_ISA_1_AVX512_VBMI2 (1U << 22)
+#define GNU_PROPERTY_X86_ISA_1_AVX512_VNNI (1U << 23)
+
+#define GNU_PROPERTY_X86_FEATURE_2_X86 (1U << 0)
+#define GNU_PROPERTY_X86_FEATURE_2_X87 (1U << 1)
+#define GNU_PROPERTY_X86_FEATURE_2_MMX (1U << 2)
+#define GNU_PROPERTY_X86_FEATURE_2_XMM (1U << 3)
+#define GNU_PROPERTY_X86_FEATURE_2_YMM (1U << 4)
+#define GNU_PROPERTY_X86_FEATURE_2_ZMM (1U << 5)
+#define GNU_PROPERTY_X86_FEATURE_2_FXSR (1U << 6)
+#define GNU_PROPERTY_X86_FEATURE_2_XSAVE (1U << 7)
+#define GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT (1U << 8)
+#define GNU_PROPERTY_X86_FEATURE_2_XSAVEC (1U << 9)
 
 /* This indicates that all executable sections are compatible with
    IBT.  */
--
2.19.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 2/2] x86/CET: Stop if the GNU_PROPERTY_X86_UINT32_VALID bit is set

H.J. Lu-30
In reply to this post by H.J. Lu-30
When updated linkers merge input .note.gnu.property sections into one
.note.gnu.property section, it sets the GNU_PROPERTY_X86_UINT32_VALID
bit in the GNU_PROPERTY_X86_FEATURE_1_AND property.  This can be used
to detect if the NT_GNU_PROPERTY_TYPE_0 note is generated by updated
linkers.  If the GNU_PROPERTY_X86_UINT32_VALID bit is set, we can stop
checking for invalid .note.gnu.property section.

        * sysdeps/x86/dl-prop.h (_dl_process_cet_property_note): Stop
        if the GNU_PROPERTY_X86_UINT32_VALID bit is set.
---
 sysdeps/x86/dl-prop.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sysdeps/x86/dl-prop.h b/sysdeps/x86/dl-prop.h
index 9ab890d12b..5c06aa5fbc 100644
--- a/sysdeps/x86/dl-prop.h
+++ b/sysdeps/x86/dl-prop.h
@@ -115,6 +115,11 @@ _dl_process_cet_property_note (struct link_map *l,
 
   feature_1 = *(unsigned int *) ptr;
 
+  /* Done if this property note is created by updated
+     linker.  */
+  if ((feature_1 & GNU_PROPERTY_X86_UINT32_VALID))
+    goto found_feature_1;
+
   /* Keep searching for the next GNU property note
      generated by the older linker.  */
   break;
@@ -138,6 +143,7 @@ _dl_process_cet_property_note (struct link_map *l,
       align));
     }
 
+found_feature_1:
   /* We get here only if there is one or no GNU property note.  */
   if ((feature_1 & GNU_PROPERTY_X86_FEATURE_1_IBT))
     l->l_cet |= lc_ibt;
--
2.19.1

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/2] elf: Update GNU_PROPERTY_X86_XXX macros [BZ #23797]

Florian Weimer-5
In reply to this post by H.J. Lu-30
* H. J. Lu:

> +/* Set by linker to indicate that the property is valid.  */
> +#define GNU_PROPERTY_X86_UINT32_VALID (1U << 31)

This should somehow say that a relocatable link (which is also performed
by the linker, via ld -r) must not set this bit.  Only the final link
may set it.

Thanks,
Florian
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/2] elf: Update GNU_PROPERTY_X86_XXX macros [BZ #23797]

H.J. Lu-30
On Fri, Nov 9, 2018 at 2:08 AM Florian Weimer <[hidden email]> wrote:

>
> * H. J. Lu:
>
> > +/* Set by linker to indicate that the property is valid.  */
> > +#define GNU_PROPERTY_X86_UINT32_VALID                (1U << 31)
>
> This should somehow say that a relocatable link (which is also performed
> by the linker, via ld -r) must not set this bit.  Only the final link
> may set it.
>
Like this?

--
H.J.

0001-elf-Update-GNU_PROPERTY_X86_XXX-macros-BZ-23797.patch (12K) Download Attachment