]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Always use align_size as pr_datasz for GNU_PROPERTY_STACK_SIZE
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 9 Aug 2018 11:29:43 +0000 (04:29 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 10 Aug 2018 15:14:24 +0000 (08:14 -0700)
For GNU_PROPERTY_STACK_SIZE, pr_datasz is the same as align_size, which
is 8 bytes for 64-bit ELF binaries and 4 bytes for 32-bit ELF binaries,
Use align_size as pr_datasz for GNU_PROPERTY_STACK_SIZE to convert
.note.gnu.property section.

bfd/

PR binutils/23494
* elf-properties.c (elf_get_gnu_property_section_size): Always
use align_size as pr_datasz for GNU_PROPERTY_STACK_SIZE.
(elf_write_gnu_properties): Likewise.

binutils/

PR binutils/23494
* testsuite/binutils-all/x86-64/pr23494c.s: New file.
* testsuite/binutils-all/x86-64/pr23494e-x32.d: Likewise.
* testsuite/binutils-all/x86-64/pr23494e.d: Likewise.

bfd/ChangeLog
bfd/elf-properties.c
binutils/ChangeLog
binutils/testsuite/binutils-all/x86-64/pr23494c.s [new file with mode: 0644]
binutils/testsuite/binutils-all/x86-64/pr23494e-x32.d [new file with mode: 0644]
binutils/testsuite/binutils-all/x86-64/pr23494e.d [new file with mode: 0644]

index d4bed23e582bf5deb81f1c79421fc0a0504ad859..20aa4f3c874ad416ff09154847502e579033ed0c 100644 (file)
@@ -1,3 +1,10 @@
+2018-08-10  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR binutils/23494
+       * elf-properties.c (elf_get_gnu_property_section_size): Always
+       use align_size as pr_datasz for GNU_PROPERTY_STACK_SIZE.
+       (elf_write_gnu_properties): Likewise.
+
 2018-08-08  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR binutils/23494
index 0ac055534d988b1811cffcb113a2b0ac4e979335..f58bdc0711e91c25b5fea98135017da3705d87f9 100644 (file)
@@ -320,7 +320,12 @@ elf_get_gnu_property_section_size (elf_property_list *list,
   for (; list != NULL; list = list->next)
     {
       /* There are 4 byte type + 4 byte datasz for each property.  */
-      size += 4 + 4 + list->property.pr_datasz;
+      unsigned int datasz;
+      if (list->property.pr_type == GNU_PROPERTY_STACK_SIZE)
+       datasz = align_size;
+      else
+       datasz = list->property.pr_datasz;
+      size += 4 + 4 + datasz;
       /* Align each property.  */
       size = (size + (align_size - 1)) & ~(align_size - 1);
     }
@@ -336,6 +341,7 @@ elf_write_gnu_properties (bfd *abfd, bfd_byte *contents,
                          unsigned int align_size)
 {
   unsigned int descsz;
+  unsigned int datasz;
   Elf_External_Note *e_note;
 
   e_note = (Elf_External_Note *) contents;
@@ -350,17 +356,19 @@ elf_write_gnu_properties (bfd *abfd, bfd_byte *contents,
   for (; list != NULL; list = list->next)
     {
       /* There are 4 byte type + 4 byte datasz for each property.  */
-      bfd_h_put_32 (abfd, list->property.pr_type,
-                   contents + size);
-      bfd_h_put_32 (abfd, list->property.pr_datasz,
-                   contents + size + 4);
+      if (list->property.pr_type == GNU_PROPERTY_STACK_SIZE)
+       datasz = align_size;
+      else
+       datasz = list->property.pr_datasz;
+      bfd_h_put_32 (abfd, list->property.pr_type, contents + size);
+      bfd_h_put_32 (abfd, datasz, contents + size + 4);
       size += 4 + 4;
 
       /* Write out property value.  */
       switch (list->property.pr_kind)
        {
        case property_number:
-         switch (list->property.pr_datasz)
+         switch (datasz)
            {
            default:
              /* Never should happen.  */
@@ -385,7 +393,7 @@ elf_write_gnu_properties (bfd *abfd, bfd_byte *contents,
          /* Never should happen.  */
          abort ();
        }
-      size += list->property.pr_datasz;
+      size += datasz;
 
       /* Align each property.  */
       size = (size + (align_size - 1)) & ~ (align_size - 1);
index b618044094a563025e7d9b04b32d45ce7e58457d..071a005134b9ee6fb696e3fc57308f4c13884780 100644 (file)
@@ -1,3 +1,10 @@
+2018-08-10  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR binutils/23494
+       * testsuite/binutils-all/x86-64/pr23494c.s: New file.
+       * testsuite/binutils-all/x86-64/pr23494e-x32.d: Likewise.
+       * testsuite/binutils-all/x86-64/pr23494e.d: Likewise.
+
 2018-08-10  H.J. Lu  <hongjiu.lu@intel.com>
 
        * testsuite/binutils-all/x86-64/pr23494a-x32.d: Skip nacl
diff --git a/binutils/testsuite/binutils-all/x86-64/pr23494c.s b/binutils/testsuite/binutils-all/x86-64/pr23494c.s
new file mode 100644 (file)
index 0000000..a478e7a
--- /dev/null
@@ -0,0 +1,123 @@
+       .section ".note.gnu.property", "a"
+.ifdef __64_bit__
+       .p2align 3
+.else
+       .p2align 2
+.endif
+       .long 1f - 0f           /* name length.  */
+       .long 3f - 1f           /* data length.  */
+       /* NT_GNU_PROPERTY_TYPE_0 */
+       .long 5                 /* note type.  */
+0:
+       .asciz "GNU"            /* vendor name.  */
+1:
+.ifdef __64_bit__
+       .p2align 3
+.else
+       .p2align 2
+.endif
+       /* GNU_PROPERTY_STACK_SIZE */
+       .long 1                 /* pr_type.  */
+       .long 5f - 4f           /* pr_datasz.  */
+4:
+       .dc.a -1
+5:
+.ifdef __64_bit__
+       .p2align 3
+.else
+       .p2align 2
+.endif
+3:
+
+       .section ".note.gnu.property", "a"
+.ifdef __64_bit__
+       .p2align 3
+.else
+       .p2align 2
+.endif
+       .long 1f - 0f           /* name length.  */
+       .long 3f - 1f           /* data length.  */
+       /* NT_GNU_PROPERTY_TYPE_0 */
+       .long 5                 /* note type.  */
+0:
+       .asciz "GNU"            /* vendor name.  */
+1:
+.ifdef __64_bit__
+       .p2align 3
+.else
+       .p2align 2
+.endif
+       /* GNU_PROPERTY_X86_ISA_1_USED */
+       .long 0xc0000000        /* pr_type.  */
+       .long 5f - 4f           /* pr_datasz.  */
+4:
+       .long 0xa
+5:
+.ifdef __64_bit__
+       .p2align 3
+.else
+       .p2align 2
+.endif
+3:
+
+       .section ".note.gnu.property", "a"
+.ifdef __64_bit__
+       .p2align 3
+.else
+       .p2align 2
+.endif
+       .long 1f - 0f           /* name length.  */
+       .long 3f - 1f           /* data length.  */
+       /* NT_GNU_PROPERTY_TYPE_0 */
+       .long 5                 /* note type.  */
+0:
+       .asciz "GNU"            /* vendor name.  */
+1:
+.ifdef __64_bit__
+       .p2align 3
+.else
+       .p2align 2
+.endif
+       /* GNU_PROPERTY_X86_ISA_1_NEEDED */
+       .long 0xc0000001        /* pr_type.  */
+       .long 5f - 4f           /* pr_datasz.  */
+4:
+       .long 0xa0
+5:
+.ifdef __64_bit__
+       .p2align 3
+.else
+       .p2align 2
+.endif
+3:
+
+       .section ".note.gnu.property", "a"
+.ifdef __64_bit__
+       .p2align 3
+.else
+       .p2align 2
+.endif
+       .long 1f - 0f           /* name length.  */
+       .long 3f - 1f           /* data length.  */
+       /* NT_GNU_PROPERTY_TYPE_0 */
+       .long 5                 /* note type.  */
+0:
+       .asciz "GNU"            /* vendor name.  */
+1:
+.ifdef __64_bit__
+       .p2align 3
+.else
+       .p2align 2
+.endif
+       /* GNU_PROPERTY_X86_ISA_1_USED */
+       .long 0xc0000000        /* pr_type.  */
+       .long 5f - 4f           /* pr_datasz.  */
+4:
+       .long 0xa0
+5:
+.ifdef __64_bit__
+       .p2align 3
+.else
+       .p2align 2
+.endif
+3:
diff --git a/binutils/testsuite/binutils-all/x86-64/pr23494e-x32.d b/binutils/testsuite/binutils-all/x86-64/pr23494e-x32.d
new file mode 100644 (file)
index 0000000..825f45d
--- /dev/null
@@ -0,0 +1,13 @@
+#PROG: objcopy
+#source: pr23494c.s
+#as: --x32
+#objcopy: -O elf64-x86-64 --decompress-debug-sections
+#readelf: -n
+#not-target: x86_64-*-nacl*
+
+Displaying notes found in: .note.gnu.property
+  Owner                 Data size      Description
+  GNU                  0x00000030      NT_GNU_PROPERTY_TYPE_0
+      Properties: stack size: 0xffffffff
+       x86 ISA used: 586, SSE, SSE3, SSE4_1
+       x86 ISA needed: SSE3, SSE4_1
diff --git a/binutils/testsuite/binutils-all/x86-64/pr23494e.d b/binutils/testsuite/binutils-all/x86-64/pr23494e.d
new file mode 100644 (file)
index 0000000..ffb8988
--- /dev/null
@@ -0,0 +1,13 @@
+#PROG: objcopy
+#source: pr23494c.s
+#as: --64 -defsym __64_bit__=1
+#objcopy: -O elf32-x86-64 --decompress-debug-sections
+#readelf: -n
+#not-target: x86_64-*-nacl*
+
+Displaying notes found in: .note.gnu.property
+  Owner                 Data size      Description
+  GNU                  0x00000024      NT_GNU_PROPERTY_TYPE_0
+      Properties: stack size: 0xffffffff
+       x86 ISA used: 586, SSE, SSE3, SSE4_1
+       x86 ISA needed: SSE3, SSE4_1