+2017-03-08 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR binutils/21231
+ * readelf.c (decode_x86_isa): Change argument to unsigned int.
+ (print_gnu_property_note): Retrieve property type and datasz as
+ 4-byte integer. Consolidate property datasz check. Check
+ GNU_PROPERTY_LOPROC and GNU_PROPERTY_LOUSER.
+ * testsuite/binutils-all/i386/pr21231a.d: New file.
+ * testsuite/binutils-all/i386/pr21231a.s: Likewise.
+ * testsuite/binutils-all/i386/pr21231b.d: Likewise.
+ * testsuite/binutils-all/i386/pr21231b.s: Likewise.
+ * testsuite/binutils-all/x86-64/pr21231a.d: Likewise.
+ * testsuite/binutils-all/x86-64/pr21231a.s: Likewise.
+ * testsuite/binutils-all/x86-64/pr21231b.d: Likewise.
+ * testsuite/binutils-all/x86-64/pr21231b.s: Likewise.
+
2017-03-06 Nick Clifton <nickc@redhat.com>
* readelf.c (print_gnu_build_attribute_name): Read byte values
}
static void
-decode_x86_isa (unsigned long bitmask)
+decode_x86_isa (unsigned int bitmask)
{
while (bitmask)
{
- unsigned long bit = bitmask & (- bitmask);
+ unsigned int bit = bitmask & (- bitmask);
bitmask &= ~ bit;
switch (bit)
case GNU_PROPERTY_X86_ISA_1_AVX512VL: printf ("AVX512VL"); break;
case GNU_PROPERTY_X86_ISA_1_AVX512DQ: printf ("AVX512DQ"); break;
case GNU_PROPERTY_X86_ISA_1_AVX512BW: printf ("AVX512BW"); break;
- default: printf (_("<unknown: %lx>"), bit); break;
+ default: printf (_("<unknown: %x>"), bit); break;
}
if (bitmask)
printf (", ");
printf (_(" Properties: "));
- if (pnote->descsz % size)
+ if (pnote->descsz < 8 || (pnote->descsz % size) != 0)
{
printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote->descsz);
return;
}
- while (ptr < (ptr_end - (size * 2)))
+ while (1)
{
- unsigned long j;
- unsigned long type = byte_get (ptr, size);
- unsigned long datasz = byte_get (ptr + size, size);
+ unsigned int j;
+ unsigned int type = byte_get (ptr, 4);
+ unsigned int datasz = byte_get (ptr + 4, 4);
- ptr += 2 * size;
+ ptr += 8;
- switch (type)
+ if ((ptr + datasz) > ptr_end)
{
- case GNU_PROPERTY_STACK_SIZE:
- printf (_("stack size: "));
- if (datasz != size || (ptr + size > ptr_end))
- printf (_("<corrupt length: %#lx> "), datasz);
- else
- printf ("%#lx", (unsigned long) byte_get (ptr, size));
- break;
-
- case GNU_PROPERTY_NO_COPY_ON_PROTECTED:
- printf ("no copy on protected ");
- if (datasz)
- printf (_("<corrupt length: %#lx> "), datasz);
+ printf (_("<corrupt type (%#x) datasz: %#x>\n"),
+ type, datasz);
break;
+ }
- case GNU_PROPERTY_X86_ISA_1_USED:
- printf ("x86 ISA used: ");
- if (datasz != size || (ptr + size > ptr_end))
- printf (_("<corrupt length: %#lx> "), datasz);
- else
- decode_x86_isa (byte_get (ptr, size));
- break;
+ if (type >= GNU_PROPERTY_LOPROC && type <= GNU_PROPERTY_HIPROC)
+ {
+ if (elf_header.e_machine == EM_X86_64
+ || elf_header.e_machine == EM_IAMCU
+ || elf_header.e_machine == EM_386)
+ {
+ switch (type)
+ {
+ case GNU_PROPERTY_X86_ISA_1_USED:
+ printf ("x86 ISA used: ");
+ if (datasz != 4)
+ printf (_("<corrupt length: %#x> "), datasz);
+ else
+ decode_x86_isa (byte_get (ptr, 4));
+ goto next;
- case GNU_PROPERTY_X86_ISA_1_NEEDED:
- printf ("x86 ISA needed: ");
- if (datasz != size || (ptr + size > ptr_end))
- printf (_("<corrupt length: %#lx> "), datasz);
- else
- decode_x86_isa (byte_get (ptr, size));
- break;
+ case GNU_PROPERTY_X86_ISA_1_NEEDED:
+ printf ("x86 ISA needed: ");
+ if (datasz != 4)
+ printf (_("<corrupt length: %#x> "), datasz);
+ else
+ decode_x86_isa (byte_get (ptr, 4));
+ goto next;
- default:
- printf (_("<unknown type %#lx data: "), type);
- if (ptr + datasz > ptr_end)
+ default:
+ break;
+ }
+ }
+ }
+ else
+ {
+ switch (type)
{
- printf (_("corrupt datasz: %#lx>\n"), datasz);
+ case GNU_PROPERTY_STACK_SIZE:
+ printf (_("stack size: "));
+ if (datasz != size)
+ printf (_("<corrupt length: %#x> "), datasz);
+ else
+ printf ("%#lx", (unsigned long) byte_get (ptr, size));
+ goto next;
+
+ case GNU_PROPERTY_NO_COPY_ON_PROTECTED:
+ printf ("no copy on protected ");
+ if (datasz)
+ printf (_("<corrupt length: %#x> "), datasz);
+ goto next;
+
+ default:
break;
}
- for (j = 0; j < datasz; ++j)
- printf ("%02x ", ptr[j] & 0xff);
- printf (">");
- break;
}
+ if (type < GNU_PROPERTY_LOPROC)
+ printf (_("<unknown type %#x data: "), type);
+ else if (type < GNU_PROPERTY_LOUSER)
+ printf (_("<procesor-specific type %#x data: "), type);
+ else
+ printf (_("<application-specific type %#x data: "), type);
+ for (j = 0; j < datasz; ++j)
+ printf ("%02x ", ptr[j] & 0xff);
+ printf (">");
+
+next:
ptr += ((datasz + (size - 1)) & ~ (size - 1));
- if (ptr < (ptr_end - (size * 2)))
+ if (ptr == ptr_end)
+ break;
+ else
{
if (do_wide)
printf (", ");
else
printf ("\n\t");
}
+
+ if (ptr > (ptr_end - 8))
+ {
+ printf (_("<corrupt descsz: %#lx>\n"), pnote->descsz);
+ break;
+ }
}
printf ("\n");
--- /dev/null
+#PROG: objcopy
+#as: --32
+#objcopy:
+#readelf: -n
+
+Displaying notes found in: .note.gnu.property
+ Owner Data size Description
+ GNU 0x00000008 NT_GNU_PROPERTY_TYPE_0
+ Properties: no copy on protected
--- /dev/null
+ .section ".note.gnu.property", "a"
+ .p2align 2
+ .long 1f - 0f /* name length. */
+ .long 5f - 2f /* data length. */
+ /* NT_GNU_PROPERTY_TYPE_0 */
+ .long 5 /* note type. */
+0: .asciz "GNU" /* vendor name. */
+1: .p2align 2
+2:
+ /* GNU_PROPERTY_NO_COPY_ON_PROTECTED */
+ .long 2 /* pr_type. */
+ .long 0 /* pr_datasz. */
+ .p2align 2
+5:
--- /dev/null
+#PROG: objcopy
+#as: --32
+#objcopy:
+#readelf: -n
+
+Displaying notes found in: .note.gnu.property
+ Owner Data size Description
+ GNU 0x0000002c NT_GNU_PROPERTY_TYPE_0
+ Properties: stack size: 0x800000
+ no copy on protected
+ x86 ISA used: i486, 586, 686, SSE, SSE2, SSE3, SSSE3, SSE4_1, SSE4_2, AVX, AVX2, AVX512F, AVX512CD, AVX512ER, AVX512PF, AVX512VL, AVX512DQ, AVX512BW, <unknown: 40000>, <unknown: 80000>, <unknown: 100000>, <unknown: 200000>, <unknown: 400000>, <unknown: 800000>, <unknown: 1000000>, <unknown: 2000000>, <unknown: 4000000>, <unknown: 8000000>, <unknown: 10000000>, <unknown: 20000000>, <unknown: 40000000>, <unknown: 80000000>
+ x86 ISA needed: i486, 586, 686, SSE, SSE2, SSE3, SSSE3, SSE4_1, SSE4_2, AVX, AVX2, AVX512F, AVX512CD, AVX512ER, AVX512PF, AVX512VL
--- /dev/null
+ .section ".note.gnu.property", "a"
+ .p2align 2
+ .long 1f - 0f /* name length. */
+ .long 5f - 2f /* data length. */
+ /* NT_GNU_PROPERTY_TYPE_0 */
+ .long 5 /* note type. */
+0: .asciz "GNU" /* vendor name. */
+1: .p2align 2
+2:
+ /* GNU_PROPERTY_STACK_SIZE */
+ .long 1 /* pr_type. */
+ .long 4f - 3f /* pr_datasz. */
+3:
+ .dc.a 0x800000 /* Stack size. */
+4:
+ .p2align 2
+ /* GNU_PROPERTY_NO_COPY_ON_PROTECTED */
+ .long 2 /* pr_type. */
+ .long 0 /* pr_datasz. */
+ .p2align 2
+ /* GNU_PROPERTY_X86_ISA_1_USED */
+ .long 0xc0000000 /* pr_type. */
+ .long 4f - 3f /* pr_datasz. */
+3:
+ .long -1
+4:
+ .p2align 2
+ /* GNU_PROPERTY_X86_ISA_1_NEEDED */
+ .long 0xc0000001 /* pr_type. */
+ .long 4f - 3f /* pr_datasz. */
+3:
+ .long 0xffff
+4:
+ .p2align 2
+5:
--- /dev/null
+#PROG: objcopy
+#as: --64
+#objcopy:
+#readelf: -n
+
+Displaying notes found in: .note.gnu.property
+ Owner Data size Description
+ GNU 0x00000008 NT_GNU_PROPERTY_TYPE_0
+ Properties: no copy on protected
--- /dev/null
+ .section ".note.gnu.property", "a"
+ .p2align 3
+ .long 1f - 0f /* name length. */
+ .long 5f - 2f /* data length. */
+ /* NT_GNU_PROPERTY_TYPE_0 */
+ .long 5 /* note type. */
+0: .asciz "GNU" /* vendor name. */
+1: .p2align 3
+2:
+ /* GNU_PROPERTY_NO_COPY_ON_PROTECTED */
+ .long 2 /* pr_type. */
+ .long 0 /* pr_datasz. */
+ .p2align 3
+5:
--- /dev/null
+#PROG: objcopy
+#as: --64
+#objcopy:
+#readelf: -n
+
+Displaying notes found in: .note.gnu.property
+ Owner Data size Description
+ GNU 0x00000038 NT_GNU_PROPERTY_TYPE_0
+ Properties: stack size: 0x800000
+ no copy on protected
+ x86 ISA used: i486, 586, 686, SSE, SSE2, SSE3, SSSE3, SSE4_1, SSE4_2, AVX, AVX2, AVX512F, AVX512CD, AVX512ER, AVX512PF, AVX512VL, AVX512DQ, AVX512BW, <unknown: 40000>, <unknown: 80000>, <unknown: 100000>, <unknown: 200000>, <unknown: 400000>, <unknown: 800000>, <unknown: 1000000>, <unknown: 2000000>, <unknown: 4000000>, <unknown: 8000000>, <unknown: 10000000>, <unknown: 20000000>, <unknown: 40000000>, <unknown: 80000000>
+ x86 ISA needed: i486, 586, 686, SSE, SSE2, SSE3, SSSE3, SSE4_1, SSE4_2, AVX, AVX2, AVX512F, AVX512CD, AVX512ER, AVX512PF, AVX512VL
--- /dev/null
+ .section ".note.gnu.property", "a"
+ .p2align 3
+ .long 1f - 0f /* name length. */
+ .long 5f - 2f /* data length. */
+ /* NT_GNU_PROPERTY_TYPE_0 */
+ .long 5 /* note type. */
+0: .asciz "GNU" /* vendor name. */
+1: .p2align 3
+2:
+ /* GNU_PROPERTY_STACK_SIZE */
+ .long 1 /* pr_type. */
+ .long 4f - 3f /* pr_datasz. */
+3:
+ .dc.a 0x800000 /* Stack size. */
+4:
+ .p2align 3
+ /* GNU_PROPERTY_NO_COPY_ON_PROTECTED */
+ .long 2 /* pr_type. */
+ .long 0 /* pr_datasz. */
+ .p2align 3
+ /* GNU_PROPERTY_X86_ISA_1_USED */
+ .long 0xc0000000 /* pr_type. */
+ .long 4f - 3f /* pr_datasz. */
+3:
+ .long -1
+4:
+ .p2align 3
+ /* GNU_PROPERTY_X86_ISA_1_NEEDED */
+ .long 0xc0000001 /* pr_type. */
+ .long 4f - 3f /* pr_datasz. */
+3:
+ .long 0xffff
+4:
+ .p2align 3
+5:
+2017-03-08 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR binutils/21231
+ * elf/common.h (GNU_PROPERTY_LOPROC): New.
+ (GNU_PROPERTY_HIPROC): Likewise.
+ (GNU_PROPERTY_LOUSER): Likewise.
+ (GNU_PROPERTY_HIUSER): Likewise.
+
2017-03-01 Nick Clifton <nickc@redhat.com>
* elf/common.h (SHF_GNU_BUILD_NOTE): Define.
/* Values used in GNU .note.gnu.property notes (NT_GNU_PROPERTY_TYPE_0). */
#define GNU_PROPERTY_STACK_SIZE 1
#define GNU_PROPERTY_NO_COPY_ON_PROTECTED 2
+
+/* Processor-specific semantics, lo */
+#define GNU_PROPERTY_LOPROC 0xc0000000
+/* Processor-specific semantics, hi */
+#define GNU_PROPERTY_HIPROC 0xdfffffff
+/* Application-specific semantics, lo */
+#define GNU_PROPERTY_LOUSER 0xe0000000
+/* Application-specific semantics, hi */
+#define GNU_PROPERTY_HIUSER 0xffffffff
+
#define GNU_PROPERTY_X86_ISA_1_USED 0xc0000000
#define GNU_PROPERTY_X86_ISA_1_NEEDED 0xc0000001