aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2017-03-08 07:44:04 -0800
committerH.J. Lu <hjl.tools@gmail.com>2017-03-08 07:44:17 -0800
commit1fc87489b40b3100badf184a7c266387bae47def (patch)
tree0b929911ff8427f908a0dbd180e473f589bcdc98
parent2e86a2830cfef688a27e17353b84f59f8147ab23 (diff)
downloadfsf-binutils-gdb-1fc87489b40b3100badf184a7c266387bae47def.zip
fsf-binutils-gdb-1fc87489b40b3100badf184a7c266387bae47def.tar.gz
fsf-binutils-gdb-1fc87489b40b3100badf184a7c266387bae47def.tar.bz2
Properly dump NT_GNU_PROPERTY_TYPE_0
Property type and datasz are always 4 bytes for both 32-bit and 64-bit objects. Property values for GNU_PROPERTY_X86_ISA_1_USED and GNU_PROPERTY_X86_ISA_1_NEEDED are 4 bytes for both i386 and x86-64 objects. We should also check GNU_PROPERTY_LOPROC and GNU_PROPERTY_LOUSER. binutils/ 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. include/ PR binutils/21231 * elf/common.h (GNU_PROPERTY_LOPROC): New. (GNU_PROPERTY_HIPROC): Likewise. (GNU_PROPERTY_LOUSER): Likewise. (GNU_PROPERTY_HIUSER): Likewise.
-rw-r--r--binutils/ChangeLog16
-rw-r--r--binutils/readelf.c123
-rw-r--r--binutils/testsuite/binutils-all/i386/pr21231a.d9
-rw-r--r--binutils/testsuite/binutils-all/i386/pr21231a.s14
-rw-r--r--binutils/testsuite/binutils-all/i386/pr21231b.d12
-rw-r--r--binutils/testsuite/binutils-all/i386/pr21231b.s35
-rw-r--r--binutils/testsuite/binutils-all/x86-64/pr21231a.d9
-rw-r--r--binutils/testsuite/binutils-all/x86-64/pr21231a.s14
-rw-r--r--binutils/testsuite/binutils-all/x86-64/pr21231b.d12
-rw-r--r--binutils/testsuite/binutils-all/x86-64/pr21231b.s35
-rw-r--r--include/ChangeLog8
-rw-r--r--include/elf/common.h10
12 files changed, 252 insertions, 45 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 6a1c269..56ca002 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,19 @@
+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
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 9ed8d41..bf5185a 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -15926,11 +15926,11 @@ get_gnu_elf_note_type (unsigned e_type)
}
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)
@@ -15953,7 +15953,7 @@ decode_x86_isa (unsigned long bitmask)
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 (", ");
@@ -15969,73 +15969,106 @@ print_gnu_property_note (Elf_Internal_Note * pnote)
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");
diff --git a/binutils/testsuite/binutils-all/i386/pr21231a.d b/binutils/testsuite/binutils-all/i386/pr21231a.d
new file mode 100644
index 0000000..7c13b85
--- /dev/null
+++ b/binutils/testsuite/binutils-all/i386/pr21231a.d
@@ -0,0 +1,9 @@
+#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
diff --git a/binutils/testsuite/binutils-all/i386/pr21231a.s b/binutils/testsuite/binutils-all/i386/pr21231a.s
new file mode 100644
index 0000000..c2510af
--- /dev/null
+++ b/binutils/testsuite/binutils-all/i386/pr21231a.s
@@ -0,0 +1,14 @@
+ .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:
diff --git a/binutils/testsuite/binutils-all/i386/pr21231b.d b/binutils/testsuite/binutils-all/i386/pr21231b.d
new file mode 100644
index 0000000..29a8f44
--- /dev/null
+++ b/binutils/testsuite/binutils-all/i386/pr21231b.d
@@ -0,0 +1,12 @@
+#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
diff --git a/binutils/testsuite/binutils-all/i386/pr21231b.s b/binutils/testsuite/binutils-all/i386/pr21231b.s
new file mode 100644
index 0000000..3d54745
--- /dev/null
+++ b/binutils/testsuite/binutils-all/i386/pr21231b.s
@@ -0,0 +1,35 @@
+ .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:
diff --git a/binutils/testsuite/binutils-all/x86-64/pr21231a.d b/binutils/testsuite/binutils-all/x86-64/pr21231a.d
new file mode 100644
index 0000000..2a00048
--- /dev/null
+++ b/binutils/testsuite/binutils-all/x86-64/pr21231a.d
@@ -0,0 +1,9 @@
+#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
diff --git a/binutils/testsuite/binutils-all/x86-64/pr21231a.s b/binutils/testsuite/binutils-all/x86-64/pr21231a.s
new file mode 100644
index 0000000..fef44e9
--- /dev/null
+++ b/binutils/testsuite/binutils-all/x86-64/pr21231a.s
@@ -0,0 +1,14 @@
+ .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:
diff --git a/binutils/testsuite/binutils-all/x86-64/pr21231b.d b/binutils/testsuite/binutils-all/x86-64/pr21231b.d
new file mode 100644
index 0000000..9d7761c
--- /dev/null
+++ b/binutils/testsuite/binutils-all/x86-64/pr21231b.d
@@ -0,0 +1,12 @@
+#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
diff --git a/binutils/testsuite/binutils-all/x86-64/pr21231b.s b/binutils/testsuite/binutils-all/x86-64/pr21231b.s
new file mode 100644
index 0000000..afba4de
--- /dev/null
+++ b/binutils/testsuite/binutils-all/x86-64/pr21231b.s
@@ -0,0 +1,35 @@
+ .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:
diff --git a/include/ChangeLog b/include/ChangeLog
index 904c20a..2cdad3f 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,3 +1,11 @@
+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.
diff --git a/include/elf/common.h b/include/elf/common.h
index 2b9bca6..f45c256 100644
--- a/include/elf/common.h
+++ b/include/elf/common.h
@@ -695,6 +695,16 @@
/* 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