x86: Remove x86 ISA properties with empty bits
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 5 Jul 2018 16:24:07 +0000 (09:24 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 5 Jul 2018 16:24:18 +0000 (09:24 -0700)
There is no need to generate x86 ISA properties with empty bits in
linker output.

bfd/

PR ld/23372
* elfxx-x86.c (_bfd_x86_elf_merge_gnu_properties): Remove x86
ISA properties with empty bits.

ld/

PR ld/23372
* testsuite/ld-i386/i386.exp: Run pr23372a and pr23372b.
* testsuite/ld-i386/pr23372a.d: New file.
* testsuite/ld-i386/pr23372a.s: Likewise.
* testsuite/ld-i386/pr23372b.d: Likewise.
* testsuite/ld-i386/pr23372b.s: Likewise.
* testsuite/ld-i386/pr23372c.s: Likewise.
* testsuite/ld-x86-64/pr23372a-x32.d: Likewise.
* testsuite/ld-x86-64/pr23372a.d: Likewise.
* testsuite/ld-x86-64/pr23372a.s: Likewise.
* testsuite/ld-x86-64/pr23372b-x32.d: Likewise.
* testsuite/ld-x86-64/pr23372b.d: Likewise.
* testsuite/ld-x86-64/pr23372b.s: Likewise.
* testsuite/ld-x86-64/pr23372c.s: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run pr23372a, pr23372a-x32,
pr23372b and pr23372b-x32.

17 files changed:
bfd/ChangeLog
bfd/elfxx-x86.c
ld/ChangeLog
ld/testsuite/ld-i386/i386.exp
ld/testsuite/ld-i386/pr23372a.d [new file with mode: 0644]
ld/testsuite/ld-i386/pr23372a.s [new file with mode: 0644]
ld/testsuite/ld-i386/pr23372b.d [new file with mode: 0644]
ld/testsuite/ld-i386/pr23372b.s [new file with mode: 0644]
ld/testsuite/ld-i386/pr23372c.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr23372a-x32.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr23372a.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr23372a.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr23372b-x32.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr23372b.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr23372b.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr23372c.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp

index ebc5eb725db0ebf0c156052c7fe84c8dbd25f10f..36e12e785dc56ffcd744cede6d8dc288e7791221 100644 (file)
@@ -1,3 +1,9 @@
+2018-07-05  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/23372
+       * elfxx-x86.c (_bfd_x86_elf_merge_gnu_properties): Remove x86
+       ISA properties with empty bits.
+
 2018-07-05  Nick Clifton  <nickc@redhat.com>
 
        * po/ru.po: Updated Russian translation.
index 827bb6c1763363973847261a9aef41d756d4e60a..a2497aab8630a0fd675f515577f5e89e487fb4ae 100644 (file)
@@ -2412,13 +2412,34 @@ _bfd_x86_elf_merge_gnu_properties (struct bfd_link_info *info,
        {
          number = aprop->u.number;
          aprop->u.number = number | bprop->u.number;
-         updated = number != (unsigned int) aprop->u.number;
+         /* Remove the property if ISA bits are empty.  */
+         if (aprop->u.number == 0)
+           {
+             aprop->pr_kind = property_remove;
+             updated = TRUE;
+           }
+         else
+           updated = number != (unsigned int) aprop->u.number;
        }
       else
        {
-         /* Return TRUE if APROP is NULL to indicate that BPROP should
-            be added to ABFD.  */
-         updated = aprop == NULL;
+         /* Only one of APROP and BPROP can be NULL.  */
+         if (aprop != NULL)
+           {
+             if (aprop->u.number == 0)
+               {
+                 /* Remove APROP if ISA bits are empty.  */
+                 aprop->pr_kind = property_remove;
+                 updated = TRUE;
+               }
+           }
+         else
+           {
+             /* Return TRUE if APROP is NULL and ISA bits of BPROP
+                aren't empty to indicate that BPROP should be added
+                to ABFD.  */
+             updated = bprop->u.number != 0;
+           }
        }
       break;
 
index a7143cdd4531f410d2cd109c66cfb2e52a4e6741..d90c8d842f28ab394589ad5b14f93378205991f3 100644 (file)
@@ -1,3 +1,22 @@
+2018-07-05  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/23372
+       * testsuite/ld-i386/i386.exp: Run pr23372a and pr23372b.
+       * testsuite/ld-i386/pr23372a.d: New file.
+       * testsuite/ld-i386/pr23372a.s: Likewise.
+       * testsuite/ld-i386/pr23372b.d: Likewise.
+       * testsuite/ld-i386/pr23372b.s: Likewise.
+       * testsuite/ld-i386/pr23372c.s: Likewise.
+       * testsuite/ld-x86-64/pr23372a-x32.d: Likewise.
+       * testsuite/ld-x86-64/pr23372a.d: Likewise.
+       * testsuite/ld-x86-64/pr23372a.s: Likewise.
+       * testsuite/ld-x86-64/pr23372b-x32.d: Likewise.
+       * testsuite/ld-x86-64/pr23372b.d: Likewise.
+       * testsuite/ld-x86-64/pr23372b.s: Likewise.
+       * testsuite/ld-x86-64/pr23372c.s: Likewise.
+       * testsuite/ld-x86-64/x86-64.exp: Run pr23372a, pr23372a-x32,
+       pr23372b and pr23372b-x32.
+
 2018-07-05  Nick Clifton  <nickc@redhat.com>
 
        * po/bg.po: Updated Bulgarian translation.
index bb91a760ca2203737bad6b493cf7340fac9a8723..6d794fe653a4f3db7092397483679dc02095b38d 100644 (file)
@@ -460,6 +460,8 @@ run_dump_test "pr22782"
 run_dump_test "pr22929"
 run_dump_test "pr23189"
 run_dump_test "pr23194"
+run_dump_test "pr23372a"
+run_dump_test "pr23372b"
 
 if { !([istarget "i?86-*-linux*"]
        || [istarget "i?86-*-gnu*"]
diff --git a/ld/testsuite/ld-i386/pr23372a.d b/ld/testsuite/ld-i386/pr23372a.d
new file mode 100644 (file)
index 0000000..b75523b
--- /dev/null
@@ -0,0 +1,5 @@
+#source: pr23372a.s
+#source: pr23372b.s
+#as: --32
+#ld: -r -m elf_i386
+#readelf: -n
diff --git a/ld/testsuite/ld-i386/pr23372a.s b/ld/testsuite/ld-i386/pr23372a.s
new file mode 100644 (file)
index 0000000..9849d62
--- /dev/null
@@ -0,0 +1,18 @@
+       .section ".note.gnu.property", "a"
+       .p2align 2
+       .long 1f - 0f           /* name length.  */
+       .long 4f - 1f           /* data length.  */
+       /* NT_GNU_PROPERTY_TYPE_0 */
+       .long 5                 /* note type.  */
+0:
+       .asciz "GNU"            /* vendor name.  */
+1:
+       .p2align 2
+       /* GNU_PROPERTY_X86_ISA_1_USED */
+       .long 0xc0000000        /* pr_type.  */
+       .long 3f - 2f           /* pr_datasz.  */
+2:
+       .long 0x0
+3:
+       .p2align 2
+4:
diff --git a/ld/testsuite/ld-i386/pr23372b.d b/ld/testsuite/ld-i386/pr23372b.d
new file mode 100644 (file)
index 0000000..a8e9c81
--- /dev/null
@@ -0,0 +1,5 @@
+#source: pr23372a.s
+#source: pr23372c.s
+#as: --32
+#ld: -r -m elf_i386
+#readelf: -n
diff --git a/ld/testsuite/ld-i386/pr23372b.s b/ld/testsuite/ld-i386/pr23372b.s
new file mode 100644 (file)
index 0000000..9849d62
--- /dev/null
@@ -0,0 +1,18 @@
+       .section ".note.gnu.property", "a"
+       .p2align 2
+       .long 1f - 0f           /* name length.  */
+       .long 4f - 1f           /* data length.  */
+       /* NT_GNU_PROPERTY_TYPE_0 */
+       .long 5                 /* note type.  */
+0:
+       .asciz "GNU"            /* vendor name.  */
+1:
+       .p2align 2
+       /* GNU_PROPERTY_X86_ISA_1_USED */
+       .long 0xc0000000        /* pr_type.  */
+       .long 3f - 2f           /* pr_datasz.  */
+2:
+       .long 0x0
+3:
+       .p2align 2
+4:
diff --git a/ld/testsuite/ld-i386/pr23372c.s b/ld/testsuite/ld-i386/pr23372c.s
new file mode 100644 (file)
index 0000000..3470dce
--- /dev/null
@@ -0,0 +1,18 @@
+       .section ".note.gnu.property", "a"
+       .p2align 2
+       .long 1f - 0f           /* name length.  */
+       .long 4f - 1f           /* data length.  */
+       /* NT_GNU_PROPERTY_TYPE_0 */
+       .long 5                 /* note type.  */
+0:
+       .asciz "GNU"            /* vendor name.  */
+1:
+       .p2align 2
+       /* GNU_PROPERTY_X86_ISA_1_NEEDED */
+       .long 0xc0000001        /* pr_type.  */
+       .long 3f - 2f           /* pr_datasz.  */
+2:
+       .long 0x0
+3:
+       .p2align 2
+4:
diff --git a/ld/testsuite/ld-x86-64/pr23372a-x32.d b/ld/testsuite/ld-x86-64/pr23372a-x32.d
new file mode 100644 (file)
index 0000000..9f93642
--- /dev/null
@@ -0,0 +1,5 @@
+#source: pr23372a.s
+#source: pr23372b.s
+#as: --x32
+#ld: -r -m elf32_x86_64
+#readelf: -n
diff --git a/ld/testsuite/ld-x86-64/pr23372a.d b/ld/testsuite/ld-x86-64/pr23372a.d
new file mode 100644 (file)
index 0000000..ee688fc
--- /dev/null
@@ -0,0 +1,5 @@
+#source: pr23372a.s
+#source: pr23372b.s
+#as: --64 -defsym __64_bit__=1
+#ld: -r -m elf_x86_64
+#readelf: -n
diff --git a/ld/testsuite/ld-x86-64/pr23372a.s b/ld/testsuite/ld-x86-64/pr23372a.s
new file mode 100644 (file)
index 0000000..639fc26
--- /dev/null
@@ -0,0 +1,30 @@
+       .section ".note.gnu.property", "a"
+.ifdef __64_bit__
+       .p2align 3
+.else
+       .p2align 2
+.endif
+       .long 1f - 0f           /* name length.  */
+       .long 4f - 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 3f - 2f           /* pr_datasz.  */
+2:
+       .long 0x0
+3:
+.ifdef __64_bit__
+       .p2align 3
+.else
+       .p2align 2
+.endif
+4:
diff --git a/ld/testsuite/ld-x86-64/pr23372b-x32.d b/ld/testsuite/ld-x86-64/pr23372b-x32.d
new file mode 100644 (file)
index 0000000..5b0cf98
--- /dev/null
@@ -0,0 +1,5 @@
+#source: pr23372a.s
+#source: pr23372c.s
+#as: --x32
+#ld: -r -m elf32_x86_64
+#readelf: -n
diff --git a/ld/testsuite/ld-x86-64/pr23372b.d b/ld/testsuite/ld-x86-64/pr23372b.d
new file mode 100644 (file)
index 0000000..727afa8
--- /dev/null
@@ -0,0 +1,5 @@
+#source: pr23372a.s
+#source: pr23372c.s
+#as: --64 -defsym __64_bit__=1
+#ld: -r -m elf_x86_64
+#readelf: -n
diff --git a/ld/testsuite/ld-x86-64/pr23372b.s b/ld/testsuite/ld-x86-64/pr23372b.s
new file mode 100644 (file)
index 0000000..639fc26
--- /dev/null
@@ -0,0 +1,30 @@
+       .section ".note.gnu.property", "a"
+.ifdef __64_bit__
+       .p2align 3
+.else
+       .p2align 2
+.endif
+       .long 1f - 0f           /* name length.  */
+       .long 4f - 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 3f - 2f           /* pr_datasz.  */
+2:
+       .long 0x0
+3:
+.ifdef __64_bit__
+       .p2align 3
+.else
+       .p2align 2
+.endif
+4:
diff --git a/ld/testsuite/ld-x86-64/pr23372c.s b/ld/testsuite/ld-x86-64/pr23372c.s
new file mode 100644 (file)
index 0000000..b4eaf69
--- /dev/null
@@ -0,0 +1,30 @@
+       .section ".note.gnu.property", "a"
+.ifdef __64_bit__
+       .p2align 3
+.else
+       .p2align 2
+.endif
+       .long 1f - 0f           /* name length.  */
+       .long 4f - 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 3f - 2f           /* pr_datasz.  */
+2:
+       .long 0x0
+3:
+.ifdef __64_bit__
+       .p2align 3
+.else
+       .p2align 2
+.endif
+4:
index e6ec049994c50489db0068fb041122258d588dc9..6edb9e86f45cb8bae6511d2686af3407fc2605f2 100644 (file)
@@ -399,6 +399,10 @@ run_dump_test "pr23189"
 run_dump_test "pr23194"
 run_dump_test "pr23324a"
 run_dump_test "pr23324b"
+run_dump_test "pr23372a"
+run_dump_test "pr23372a-x32"
+run_dump_test "pr23372b"
+run_dump_test "pr23372b-x32"
 
 if { ![istarget "x86_64-*-linux*"] && ![istarget "x86_64-*-nacl*"]} {
     return