[arch-commits] Commit in binutils/repos (5 files)

Evangelos Foutras foutrelis at archlinux.org
Tue Aug 7 23:18:32 UTC 2018


    Date: Tuesday, August 7, 2018 @ 23:18:31
  Author: foutrelis
Revision: 331140

archrelease: copy trunk to testing-x86_64

Added:
  binutils/repos/testing-x86_64/
  binutils/repos/testing-x86_64/0001-PR23428-x86-Add-a-GNU_PROPERTY_X86_ISA_1_USED-note-if-needed.patch
    (from rev 331139, binutils/trunk/0001-PR23428-x86-Add-a-GNU_PROPERTY_X86_ISA_1_USED-note-if-needed.patch)
  binutils/repos/testing-x86_64/0002-PR23460-Close-resource-leaks-in-the-BFD-library-s-plugin-han.patch
    (from rev 331139, binutils/trunk/0002-PR23460-Close-resource-leaks-in-the-BFD-library-s-plugin-han.patch)
  binutils/repos/testing-x86_64/0003-PR23460-Add-a-testcase-for-PR-binutils-23460.patch
    (from rev 331139, binutils/trunk/0003-PR23460-Add-a-testcase-for-PR-binutils-23460.patch)
  binutils/repos/testing-x86_64/PKGBUILD
    (from rev 331139, binutils/trunk/PKGBUILD)

-------------------------------------------------------------------------+
 0001-PR23428-x86-Add-a-GNU_PROPERTY_X86_ISA_1_USED-note-if-needed.patch |  515 ++++++++++
 0002-PR23460-Close-resource-leaks-in-the-BFD-library-s-plugin-han.patch |  104 ++
 0003-PR23460-Add-a-testcase-for-PR-binutils-23460.patch                 |  141 ++
 PKGBUILD                                                                |   92 +
 4 files changed, 852 insertions(+)

Copied: binutils/repos/testing-x86_64/0001-PR23428-x86-Add-a-GNU_PROPERTY_X86_ISA_1_USED-note-if-needed.patch (from rev 331139, binutils/trunk/0001-PR23428-x86-Add-a-GNU_PROPERTY_X86_ISA_1_USED-note-if-needed.patch)
===================================================================
--- testing-x86_64/0001-PR23428-x86-Add-a-GNU_PROPERTY_X86_ISA_1_USED-note-if-needed.patch	                        (rev 0)
+++ testing-x86_64/0001-PR23428-x86-Add-a-GNU_PROPERTY_X86_ISA_1_USED-note-if-needed.patch	2018-08-07 23:18:31 UTC (rev 331140)
@@ -0,0 +1,515 @@
+From f49ffdb448c81035e9ab285720cf74d59df2e111 Mon Sep 17 00:00:00 2001
+From: "H.J. Lu" <hjl.tools at gmail.com>
+Date: Fri, 20 Jul 2018 09:18:47 -0700
+Subject: [PATCH] x86: Add a GNU_PROPERTY_X86_ISA_1_USED note if needed
+
+When -z separate-code, which is enabled by default for Linux/x86, is
+used to create executable, ld won't place any data in the code-only
+PT_LOAD segment.  If there are no data sections placed before the
+code-only PT_LOAD segment, the program headers won't be mapped into
+any PT_LOAD segment.  When the executable tries to access it (based
+on the program header address passed in AT_PHDR), it will lead to
+segfault.  This patch inserts a GNU_PROPERTY_X86_ISA_1_USED note if
+there may be no data sections before the text section so that the
+first PT_LOAD segment won't be code-only and will contain the program
+header.
+
+Testcases are adjusted to either pass "-z noseparate-code" to ld or
+discard the .note.gnu.property section.  A Linux/x86 run-time test is
+added.
+
+bfd/
+
+	PR ld/23428
+	* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): If the
+	separate code program header is needed, make sure that the first
+	read-only PT_LOAD segment has no code by adding a
+	GNU_PROPERTY_X86_ISA_1_USED note.
+
+ld/
+
+	PR ld/23428
+	* testsuite/ld-elf/linux-x86.S: New file.
+	* testsuite/ld-elf/linux-x86.exp: Likewise.
+	* testsuite/ld-elf/pr23428.c: Likewise.
+	* testsuite/ld-elf/sec64k.exp: Pass "-z noseparate-code" to ld
+	for Linux/x86 targets.
+	* testsuite/ld-i386/abs-iamcu.d: Likewise.
+	* testsuite/ld-i386/abs.d: Likewise.
+	* testsuite/ld-i386/pr12718.d: Likewise.
+	* testsuite/ld-i386/pr12921.d: Likewise.
+	* testsuite/ld-x86-64/abs-k1om.d: Likewise.
+	* testsuite/ld-x86-64/abs-l1om.d: Likewise.
+	* testsuite/ld-x86-64/abs.d: Likewise.
+	* testsuite/ld-x86-64/pr12718.d: Likewise.
+	* testsuite/ld-x86-64/pr12921.d: Likewise.
+	* testsuite/ld-linkonce/zeroeh.ld: Discard .note.gnu.property
+	section.
+	* testsuite/ld-scripts/print-memory-usage.t: Likewise.
+	* testsuite/ld-scripts/size-2.t: Likewise.
+	* testsuite/lib/ld-lib.exp (run_ld_link_exec_tests): Use ld
+	to create executable if language is "asm".
+---
+ bfd/elfxx-x86.c                              | 60 ++++++++++++++-----
+ ld/testsuite/ld-elf/linux-x86.S              | 63 ++++++++++++++++++++
+ ld/testsuite/ld-elf/linux-x86.exp            | 46 ++++++++++++++
+ ld/testsuite/ld-elf/pr23428.c                | 43 +++++++++++++
+ ld/testsuite/ld-elf/sec64k.exp               |  2 +
+ ld/testsuite/ld-i386/abs-iamcu.d             |  2 +-
+ ld/testsuite/ld-i386/abs.d                   |  2 +-
+ ld/testsuite/ld-i386/pr12718.d               |  2 +-
+ ld/testsuite/ld-i386/pr12921.d               |  2 +-
+ ld/testsuite/ld-linkonce/zeroeh.ld           |  1 +
+ ld/testsuite/ld-scripts/print-memory-usage.t |  2 +
+ ld/testsuite/ld-scripts/size-2.t             |  1 +
+ ld/testsuite/ld-x86-64/abs-k1om.d            |  2 +-
+ ld/testsuite/ld-x86-64/abs-l1om.d            |  2 +-
+ ld/testsuite/ld-x86-64/abs.d                 |  2 +-
+ ld/testsuite/ld-x86-64/pr12718.d             |  2 +-
+ ld/testsuite/ld-x86-64/pr12921.d             |  2 +-
+ ld/testsuite/lib/ld-lib.exp                  |  5 +-
+ 18 files changed, 216 insertions(+), 25 deletions(-)
+ create mode 100644 ld/testsuite/ld-elf/linux-x86.S
+ create mode 100644 ld/testsuite/ld-elf/linux-x86.exp
+ create mode 100644 ld/testsuite/ld-elf/pr23428.c
+
+diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
+index a2497aab86..2e4ff88f1f 100644
+--- a/bfd/elfxx-x86.c
++++ b/bfd/elfxx-x86.c
+@@ -2524,6 +2524,7 @@ _bfd_x86_elf_link_setup_gnu_properties
+   const struct elf_backend_data *bed;
+   unsigned int class_align = ABI_64_P (info->output_bfd) ? 3 : 2;
+   unsigned int got_align;
++  bfd_boolean has_text = FALSE;
+ 
+   features = 0;
+   if (info->ibt)
+@@ -2538,24 +2539,59 @@ _bfd_x86_elf_link_setup_gnu_properties
+     if (bfd_get_flavour (pbfd) == bfd_target_elf_flavour
+ 	&& bfd_count_sections (pbfd) != 0)
+       {
++	if (!has_text)
++	  {
++	    /* Check if there is no non-empty text section.  */
++	    sec = bfd_get_section_by_name (pbfd, ".text");
++	    if (sec != NULL && sec->size != 0)
++	      has_text = TRUE;
++	  }
++
+ 	ebfd = pbfd;
+ 
+ 	if (elf_properties (pbfd) != NULL)
+ 	  break;
+       }
+ 
+-  if (ebfd != NULL && features)
++  bed = get_elf_backend_data (info->output_bfd);
++
++  htab = elf_x86_hash_table (info, bed->target_id);
++  if (htab == NULL)
++    return pbfd;
++
++  if (ebfd != NULL)
+     {
+-      /* If features is set, add GNU_PROPERTY_X86_FEATURE_1_IBT and
+-	 GNU_PROPERTY_X86_FEATURE_1_SHSTK.  */
+-      prop = _bfd_elf_get_property (ebfd,
+-				    GNU_PROPERTY_X86_FEATURE_1_AND,
+-				    4);
+-      prop->u.number |= features;
+-      prop->pr_kind = property_number;
++      prop = NULL;
++      if (features)
++	{
++	  /* If features is set, add GNU_PROPERTY_X86_FEATURE_1_IBT and
++	     GNU_PROPERTY_X86_FEATURE_1_SHSTK.  */
++	  prop = _bfd_elf_get_property (ebfd,
++					GNU_PROPERTY_X86_FEATURE_1_AND,
++					4);
++	  prop->u.number |= features;
++	  prop->pr_kind = property_number;
++	}
++      else if (has_text
++	       && elf_properties (ebfd) == NULL
++	       && elf_tdata (info->output_bfd)->o->build_id.sec == NULL
++	       && !htab->elf.dynamic_sections_created
++	       && !info->traditional_format
++	       && (info->output_bfd->flags & D_PAGED) != 0
++	       && info->separate_code)
++	{
++	  /* If the separate code program header is needed, make sure
++	     that the first read-only PT_LOAD segment has no code by
++	     adding a GNU_PROPERTY_X86_ISA_1_USED note.  */
++	  prop = _bfd_elf_get_property (ebfd,
++					GNU_PROPERTY_X86_ISA_1_USED,
++					4);
++	  prop->u.number = GNU_PROPERTY_X86_ISA_1_486;
++	  prop->pr_kind = property_number;
++	}
+ 
+       /* Create the GNU property note section if needed.  */
+-      if (pbfd == NULL)
++      if (prop != NULL && pbfd == NULL)
+ 	{
+ 	  sec = bfd_make_section_with_flags (ebfd,
+ 					     NOTE_GNU_PROPERTY_SECTION_NAME,
+@@ -2581,12 +2617,6 @@ error_alignment:
+ 
+   pbfd = _bfd_elf_link_setup_gnu_properties (info);
+ 
+-  bed = get_elf_backend_data (info->output_bfd);
+-
+-  htab = elf_x86_hash_table (info, bed->target_id);
+-  if (htab == NULL)
+-    return pbfd;
+-
+   htab->r_info = init_table->r_info;
+   htab->r_sym = init_table->r_sym;
+ 
+diff --git a/ld/testsuite/ld-elf/linux-x86.S b/ld/testsuite/ld-elf/linux-x86.S
+new file mode 100644
+index 0000000000..bdf40c6e01
+--- /dev/null
++++ b/ld/testsuite/ld-elf/linux-x86.S
+@@ -0,0 +1,63 @@
++	.text
++	.globl _start
++	.type _start, at function
++	.p2align 4
++_start:
++	xorl %ebp, %ebp
++#ifdef __LP64__
++	popq %rdi
++	movq %rsp, %rsi
++	andq  $~15, %rsp
++#elif defined __x86_64__
++	mov (%rsp),%edi
++	addl $4,%esp
++	movl %esp, %esi
++	andl  $~15, %esp
++#else
++	popl %esi
++	movl %esp, %ecx
++	andl  $~15, %esp
++
++	subl $8,%esp
++	pushl %ecx
++	pushl %esi
++#endif
++
++	call main
++
++	hlt
++
++	.type syscall,  @function
++	.globl syscall
++	.p2align 4
++syscall:
++#ifdef __x86_64__
++	movq %rdi, %rax		/* Syscall number -> rax.  */
++	movq %rsi, %rdi		/* shift arg1 - arg5.  */
++	movq %rdx, %rsi
++	movq %rcx, %rdx
++	movq %r8, %r10
++	movq %r9, %r8
++	movq 8(%rsp),%r9	/* arg6 is on the stack.  */
++	syscall			/* Do the system call.  */
++#else
++	push %ebp
++	push %edi
++	push %esi
++	push %ebx
++	mov 0x2c(%esp),%ebp
++	mov 0x28(%esp),%edi
++	mov 0x24(%esp),%esi
++	mov 0x20(%esp),%edx
++	mov 0x1c(%esp),%ecx
++	mov 0x18(%esp),%ebx
++	mov 0x14(%esp),%eax
++	int $0x80
++	pop %ebx
++	pop %esi
++	pop %edi
++	pop %ebp
++#endif
++	ret			/* Return to caller.  */
++	.size syscall, .-syscall
++	.section .note.GNU-stack,"", at progbits
+diff --git a/ld/testsuite/ld-elf/linux-x86.exp b/ld/testsuite/ld-elf/linux-x86.exp
+new file mode 100644
+index 0000000000..36217c6fb4
+--- /dev/null
++++ b/ld/testsuite/ld-elf/linux-x86.exp
+@@ -0,0 +1,46 @@
++# Expect script for simple native Linux/x86 tests.
++#   Copyright (C) 2018 Free Software Foundation, Inc.
++#
++# This file is part of the GNU Binutils.
++#
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program; if not, write to the Free Software
++# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
++# MA 02110-1301, USA.
++#
++
++# Test very simple native Linux/x86 programs with linux-x86.S.
++if { ![isnative] || [which $CC] == 0 \
++     || (![istarget "i?86-*-linux*"] \
++         && ![istarget "x86_64-*-linux*"] \
++         && ![istarget "amd64-*-linux*"]) } {
++    return
++}
++
++# Add $PLT_CFLAGS if PLT is expected.
++global PLT_CFLAGS
++# Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
++global NOPIE_CFLAGS NOPIE_LDFLAGS
++
++run_ld_link_exec_tests [list \
++    [list \
++	"Run PR ld/23428 test" \
++	"--no-dynamic-linker -z separate-code" \
++	"" \
++	{ linux-x86.S pr23428.c } \
++	"pr23428" \
++	"pass.out" \
++	"$NOPIE_CFLAGS -fno-asynchronous-unwind-tables" \
++	"asm" \
++    ] \
++]
+diff --git a/ld/testsuite/ld-elf/pr23428.c b/ld/testsuite/ld-elf/pr23428.c
+new file mode 100644
+index 0000000000..3631ed7926
+--- /dev/null
++++ b/ld/testsuite/ld-elf/pr23428.c
+@@ -0,0 +1,43 @@
++#include <unistd.h>
++#include <link.h>
++#include <syscall.h>
++
++#define STRING_COMMA_LEN(STR) (STR), (sizeof (STR) - 1)
++
++int
++main (int argc, char **argv)
++{
++  char **ev = &argv[argc + 1];
++  char **evp = ev;
++  ElfW(auxv_t) *av;
++  const ElfW(Phdr) *phdr = NULL;
++  size_t phnum = 0;
++  size_t loadnum = 0;
++  int fd = STDOUT_FILENO;
++  size_t i;
++
++  while (*evp++ != NULL)
++    ;
++
++  av = (ElfW(auxv_t) *) evp;
++
++  for (; av->a_type != AT_NULL; ++av)
++    switch (av->a_type)
++      {
++      case AT_PHDR:
++	phdr = (const void *) av->a_un.a_val;
++	break;
++      case AT_PHNUM:
++	phnum = av->a_un.a_val;
++	break;
++      }
++
++  for (i = 0; i < phnum; i++, phdr++)
++    if (phdr->p_type == PT_LOAD)
++      loadnum++;
++
++  syscall (SYS_write, fd, STRING_COMMA_LEN ("PASS\n"));
++
++  syscall (SYS_exit, !loadnum);
++  return 0;
++}
+diff --git a/ld/testsuite/ld-elf/sec64k.exp b/ld/testsuite/ld-elf/sec64k.exp
+index b58139e9dd..3909c0eaa1 100644
+--- a/ld/testsuite/ld-elf/sec64k.exp
++++ b/ld/testsuite/ld-elf/sec64k.exp
+@@ -177,6 +177,8 @@ if { ![istarget "d10v-*-*"]
+     foreach sfile $sfiles { puts $ofd "#source: $sfile" }
+     if { [istarget spu*-*-*] } {
+ 	puts $ofd "#ld: --local-store 0:0"
++    } elseif { [istarget "i?86-*-linux*"] || [istarget "x86_64-*-linux*"] } {
++	puts $ofd "#ld: -z noseparate-code"
+     } else {
+ 	puts $ofd "#ld:"
+     }
+diff --git a/ld/testsuite/ld-i386/abs-iamcu.d b/ld/testsuite/ld-i386/abs-iamcu.d
+index ac9beff2e5..aba7d6b03f 100644
+--- a/ld/testsuite/ld-i386/abs-iamcu.d
++++ b/ld/testsuite/ld-i386/abs-iamcu.d
+@@ -2,7 +2,7 @@
+ #source: abs.s
+ #source: zero.s
+ #as: --32 -march=iamcu
+-#ld: -m elf_iamcu
++#ld: -m elf_iamcu -z noseparate-code
+ #objdump: -rs -j .text
+ 
+ .*:     file format .*
+diff --git a/ld/testsuite/ld-i386/abs.d b/ld/testsuite/ld-i386/abs.d
+index e660aca524..191ee4456a 100644
+--- a/ld/testsuite/ld-i386/abs.d
++++ b/ld/testsuite/ld-i386/abs.d
+@@ -2,7 +2,7 @@
+ #as: --32
+ #source: abs.s
+ #source: zero.s
+-#ld: -melf_i386
++#ld: -melf_i386 -z noseparate-code
+ #objdump: -rs
+ 
+ .*:     file format .*
+diff --git a/ld/testsuite/ld-i386/pr12718.d b/ld/testsuite/ld-i386/pr12718.d
+index ec51540a42..7eba52d95e 100644
+--- a/ld/testsuite/ld-i386/pr12718.d
++++ b/ld/testsuite/ld-i386/pr12718.d
+@@ -1,6 +1,6 @@
+ #name: PR ld/12718
+ #as: --32
+-#ld: -melf_i386
++#ld: -melf_i386 -z noseparate-code
+ #readelf: -S
+ 
+ There are 5 section headers, starting at offset 0x[0-9a-f]+:
+diff --git a/ld/testsuite/ld-i386/pr12921.d b/ld/testsuite/ld-i386/pr12921.d
+index e49079b3c8..ea2da3eb51 100644
+--- a/ld/testsuite/ld-i386/pr12921.d
++++ b/ld/testsuite/ld-i386/pr12921.d
+@@ -1,6 +1,6 @@
+ #name: PR ld/12921
+ #as: --32
+-#ld: -melf_i386
++#ld: -melf_i386 -z noseparate-code
+ #readelf: -S --wide
+ 
+ There are 7 section headers, starting at offset 0x[0-9a-f]+:
+diff --git a/ld/testsuite/ld-linkonce/zeroeh.ld b/ld/testsuite/ld-linkonce/zeroeh.ld
+index b22eaa12c9..f89855a08f 100644
+--- a/ld/testsuite/ld-linkonce/zeroeh.ld
++++ b/ld/testsuite/ld-linkonce/zeroeh.ld
+@@ -2,4 +2,5 @@ SECTIONS {
+  .text 0xa00 : { *(.text); *(.gnu.linkonce.t.*) }
+  .gcc_except_table 0x2000 : { *(.gcc_except_table) }
+  .eh_frame 0x4000 : { *(.eh_frame) }
++  /DISCARD/ : { *(.note.gnu.property) }
+ }
+diff --git a/ld/testsuite/ld-scripts/print-memory-usage.t b/ld/testsuite/ld-scripts/print-memory-usage.t
+index 5ff057a5e3..6eda1d2dc4 100644
+--- a/ld/testsuite/ld-scripts/print-memory-usage.t
++++ b/ld/testsuite/ld-scripts/print-memory-usage.t
+@@ -11,4 +11,6 @@ SECTIONS
+     *(.data)
+     *(.rw)
+   }
++
++  /DISCARD/ : { *(.note.gnu.property) }
+ }
+diff --git a/ld/testsuite/ld-scripts/size-2.t b/ld/testsuite/ld-scripts/size-2.t
+index 723863995e..c3c4eddab4 100644
+--- a/ld/testsuite/ld-scripts/size-2.t
++++ b/ld/testsuite/ld-scripts/size-2.t
+@@ -18,4 +18,5 @@ SECTIONS
+     LONG (SIZEOF (.tdata))
+     LONG (SIZEOF (.tbss))
+   } :image
++  /DISCARD/ : { *(.note.gnu.property) }
+ }
+diff --git a/ld/testsuite/ld-x86-64/abs-k1om.d b/ld/testsuite/ld-x86-64/abs-k1om.d
+index 2c26639fc0..6b0fde0eed 100644
+--- a/ld/testsuite/ld-x86-64/abs-k1om.d
++++ b/ld/testsuite/ld-x86-64/abs-k1om.d
+@@ -2,7 +2,7 @@
+ #source: ../ld-i386/abs.s
+ #source: ../ld-i386/zero.s
+ #as: --64 -march=k1om
+-#ld: -m elf_k1om
++#ld: -m elf_k1om -z noseparate-code
+ #objdump: -rs -j .text
+ 
+ .*:     file format .*
+diff --git a/ld/testsuite/ld-x86-64/abs-l1om.d b/ld/testsuite/ld-x86-64/abs-l1om.d
+index 1fb96d44b7..f87869f9d0 100644
+--- a/ld/testsuite/ld-x86-64/abs-l1om.d
++++ b/ld/testsuite/ld-x86-64/abs-l1om.d
+@@ -2,7 +2,7 @@
+ #source: ../ld-i386/abs.s
+ #source: ../ld-i386/zero.s
+ #as: --64 -march=l1om
+-#ld: -m elf_l1om
++#ld: -m elf_l1om -z noseparate-code
+ #objdump: -rs -j .text
+ #target: x86_64-*-linux*
+ 
+diff --git a/ld/testsuite/ld-x86-64/abs.d b/ld/testsuite/ld-x86-64/abs.d
+index b24b018639..d99ab4685d 100644
+--- a/ld/testsuite/ld-x86-64/abs.d
++++ b/ld/testsuite/ld-x86-64/abs.d
+@@ -1,7 +1,7 @@
+ #name: Absolute non-overflowing relocs
+ #source: ../ld-i386/abs.s
+ #source: ../ld-i386/zero.s
+-#ld:
++#ld: -z noseparate-code
+ #objdump: -rs
+ 
+ .*:     file format .*
+diff --git a/ld/testsuite/ld-x86-64/pr12718.d b/ld/testsuite/ld-x86-64/pr12718.d
+index 07d17325d0..2c503ffbaa 100644
+--- a/ld/testsuite/ld-x86-64/pr12718.d
++++ b/ld/testsuite/ld-x86-64/pr12718.d
+@@ -1,6 +1,6 @@
+ #name: PR ld/12718
+ #as: --64
+-#ld: -melf_x86_64
++#ld: -melf_x86_64 -z noseparate-code
+ #readelf: -S --wide
+ 
+ There are 5 section headers, starting at offset 0x[0-9a-f]+:
+diff --git a/ld/testsuite/ld-x86-64/pr12921.d b/ld/testsuite/ld-x86-64/pr12921.d
+index 6fe6abee09..1162d55818 100644
+--- a/ld/testsuite/ld-x86-64/pr12921.d
++++ b/ld/testsuite/ld-x86-64/pr12921.d
+@@ -1,6 +1,6 @@
+ #name: PR ld/12921
+ #as: --64
+-#ld: -melf_x86_64
++#ld: -melf_x86_64 -z noseparate-code
+ #readelf: -S --wide
+ 
+ There are 7 section headers, starting at offset 0x[0-9a-f]+:
+diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
+index cfbefe9028..1095091882 100644
+--- a/ld/testsuite/lib/ld-lib.exp
++++ b/ld/testsuite/lib/ld-lib.exp
+@@ -1482,7 +1482,10 @@ proc run_ld_link_exec_tests { ldtests args } {
+ 	    continue
+ 	}
+ 
+-	if { [ string match "c++" $lang ] } {
++	if { [ string match "asm" $lang ] } {
++	    set link_proc ld_link
++	    set link_cmd $ld
++	} elseif { [ string match "c++" $lang ] } {
+ 	    set link_proc ld_link
+ 	    set link_cmd $CXX
+ 	} else {
+-- 
+2.18.0
+

Copied: binutils/repos/testing-x86_64/0002-PR23460-Close-resource-leaks-in-the-BFD-library-s-plugin-han.patch (from rev 331139, binutils/trunk/0002-PR23460-Close-resource-leaks-in-the-BFD-library-s-plugin-han.patch)
===================================================================
--- testing-x86_64/0002-PR23460-Close-resource-leaks-in-the-BFD-library-s-plugin-han.patch	                        (rev 0)
+++ testing-x86_64/0002-PR23460-Close-resource-leaks-in-the-BFD-library-s-plugin-han.patch	2018-08-07 23:18:31 UTC (rev 331140)
@@ -0,0 +1,104 @@
+From 29175af7e3859b9892e9113ea9a71e38048552e2 Mon Sep 17 00:00:00 2001
+From: Nick Clifton <nickc at redhat.com>
+Date: Wed, 1 Aug 2018 14:34:41 +0100
+Subject: [PATCH] Close resource leaks in the BFD library's plugin handler.
+
+	PR 23460
+	* plugin.c (bfd_plugin_open_input): Close file descriptor if the
+	call to fstat fails.
+	(try_claim): Always close the file descriptor at the end of the
+	function.
+	(try_load_plugin): If a plugin has already been registered, then
+	skip the dlopen and onload steps and go straight to claiming the
+	file.  If these is an error, close the plugin.
+---
+ bfd/plugin.c | 26 +++++++++++++++++++-------
+ 1 file changed, 19 insertions(+), 7 deletions(-)
+
+diff --git a/bfd/plugin.c b/bfd/plugin.c
+index 7c5bba22c7..d9b9e2f174 100644
+--- a/bfd/plugin.c
++++ b/bfd/plugin.c
+@@ -124,7 +124,7 @@ message (int level ATTRIBUTE_UNUSED,
+ }
+ 
+ /* Register a claim-file handler. */
+-static ld_plugin_claim_file_handler claim_file;
++static ld_plugin_claim_file_handler claim_file = NULL;
+ 
+ static enum ld_plugin_status
+ register_claim_file (ld_plugin_claim_file_handler handler)
+@@ -186,8 +186,13 @@ bfd_plugin_open_input (bfd *ibfd, struct ld_plugin_input_file *file)
+   if (iobfd == ibfd)
+     {
+       struct stat stat_buf;
++
+       if (fstat (file->fd, &stat_buf))
+-	return 0;
++	{
++	  close(file->fd);
++	  return 0;
++	}
++
+       file->offset = 0;
+       file->filesize = stat_buf.st_size;
+     }
+@@ -208,21 +213,24 @@ try_claim (bfd *abfd)
+   file.handle = abfd;
+   if (!bfd_plugin_open_input (abfd, &file))
+     return 0;
+-  claim_file (&file, &claimed);
+-  if (!claimed)
+-    close (file.fd);
++  if (claim_file)
++    claim_file (&file, &claimed);
++  close (file.fd);
+   return claimed;
+ }
+ 
+ static int
+ try_load_plugin (const char *pname, bfd *abfd, int *has_plugin_p)
+ {
+-  void *plugin_handle;
++  void *plugin_handle = NULL;
+   struct ld_plugin_tv tv[4];
+   int i;
+   ld_plugin_onload onload;
+   enum ld_plugin_status status;
+ 
++  if (claim_file)
++    goto have_claim_file;
++
+   *has_plugin_p = 0;
+ 
+   plugin_handle = dlopen (pname, RTLD_NOW);
+@@ -257,6 +265,7 @@ try_load_plugin (const char *pname, bfd *abfd, int *has_plugin_p)
+   if (status != LDPS_OK)
+     goto err;
+ 
++have_claim_file:
+   *has_plugin_p = 1;
+ 
+   abfd->plugin_format = bfd_plugin_no;
+@@ -272,6 +281,9 @@ try_load_plugin (const char *pname, bfd *abfd, int *has_plugin_p)
+   return 1;
+ 
+  err:
++  if (plugin_handle)
++    dlclose (plugin_handle);
++  register_claim_file (NULL);
+   return 0;
+ }
+ 
+@@ -362,7 +374,7 @@ load_plugin (bfd *abfd)
+       int valid_plugin;
+ 
+       full_name = concat (p, "/", ent->d_name, NULL);
+-      if (stat(full_name, &s) == 0 && S_ISREG (s.st_mode))
++      if (stat (full_name, &s) == 0 && S_ISREG (s.st_mode))
+ 	found = try_load_plugin (full_name, abfd, &valid_plugin);
+       if (has_plugin <= 0)
+ 	has_plugin = valid_plugin;
+-- 
+2.18.0
+

Copied: binutils/repos/testing-x86_64/0003-PR23460-Add-a-testcase-for-PR-binutils-23460.patch (from rev 331139, binutils/trunk/0003-PR23460-Add-a-testcase-for-PR-binutils-23460.patch)
===================================================================
--- testing-x86_64/0003-PR23460-Add-a-testcase-for-PR-binutils-23460.patch	                        (rev 0)
+++ testing-x86_64/0003-PR23460-Add-a-testcase-for-PR-binutils-23460.patch	2018-08-07 23:18:31 UTC (rev 331140)
@@ -0,0 +1,141 @@
+From 51096b8055c73c9cdbadfa4ad75955eab8ef91a5 Mon Sep 17 00:00:00 2001
+From: "H.J. Lu" <hjl.tools at gmail.com>
+Date: Thu, 2 Aug 2018 05:00:45 -0700
+Subject: [PATCH] Add a testcase for PR binutils/23460
+
+Add a testcase to limit open files to 16 for AR with plugin.  Before
+
+commit 103da91bc083f94769e3758175a96d06cef1f8fe
+Author: Nick Clifton <nickc at redhat.com>
+Date:   Wed Aug 1 14:34:41 2018 +0100
+
+    Close resource leaks in the BFD library's plugin handler.
+
+it failed with:
+
+../binutils/ar: tmpdir/pr23460f.o: plugin needed to handle lto object
+
+	PR binutils/23460
+	* testsuite/ld-plugin/lto.exp: Run the PR binutils/23460 test.
+	* testsuite/ld-plugin/pr23460a.c: New file.
+	* testsuite/ld-plugin/pr23460b.c: Likewise.
+	* testsuite/ld-plugin/pr23460c.c: Likewise.
+	* testsuite/ld-plugin/pr23460d.c: Likewise.
+	* testsuite/ld-plugin/pr23460e.c: Likewise.
+	* testsuite/ld-plugin/pr23460f.c: Likewise.
+---
+ ld/testsuite/ld-plugin/lto.exp    | 26 ++++++++++++++++++++++++++
+ ld/testsuite/ld-plugin/pr23460a.c |  4 ++++
+ ld/testsuite/ld-plugin/pr23460b.c |  4 ++++
+ ld/testsuite/ld-plugin/pr23460c.c |  4 ++++
+ ld/testsuite/ld-plugin/pr23460d.c |  4 ++++
+ ld/testsuite/ld-plugin/pr23460e.c |  4 ++++
+ ld/testsuite/ld-plugin/pr23460f.c |  4 ++++
+ 7 files changed, 50 insertions(+)
+ create mode 100644 ld/testsuite/ld-plugin/pr23460a.c
+ create mode 100644 ld/testsuite/ld-plugin/pr23460b.c
+ create mode 100644 ld/testsuite/ld-plugin/pr23460c.c
+ create mode 100644 ld/testsuite/ld-plugin/pr23460d.c
+ create mode 100644 ld/testsuite/ld-plugin/pr23460e.c
+ create mode 100644 ld/testsuite/ld-plugin/pr23460f.c
+
+diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
+index 7c50b0f102..5d354bfa9e 100644
+--- a/ld/testsuite/ld-plugin/lto.exp
++++ b/ld/testsuite/ld-plugin/lto.exp
+@@ -556,6 +556,32 @@ if { [at_least_gcc_version 4 7] } {
+     } {
+         fail $testname
+     }
++
++    run_cc_link_tests [list \
++	[list \
++	    "Build pr23460*.o" \
++	    "$plug_opt" \
++	    "-O2 -fPIC -flto $lto_no_fat" \
++	    {pr23460a.c pr23460b.c pr23460c.c \
++	     pr23460d.c pr23460e.c pr23460f.c} \
++	] \
++    ]
++    set exec_output [run_host_cmd "sh" \
++				  "-c \"ulimit -n 16; \
++				   $ar -rc $plug_opt \
++				   tmpdir/libpr23460.a \
++				   tmpdir/pr23460a.o \
++				   tmpdir/pr23460b.o \
++				   tmpdir/pr23460c.o \
++				   tmpdir/pr23460d.o \
++				   tmpdir/pr23460e.o \
++				   tmpdir/pr23460f.o\""]
++    set exec_output [prune_warnings $exec_output]
++    if [string match "" $exec_output] then {
++	pass "PR binutils/23460"
++    } else {
++	fail "PR binutils/23460"
++    }
+ }
+ 
+ # Run "ld -r" to generate inputs for complex LTO tests.
+diff --git a/ld/testsuite/ld-plugin/pr23460a.c b/ld/testsuite/ld-plugin/pr23460a.c
+new file mode 100644
+index 0000000000..4a8cd140a2
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/pr23460a.c
+@@ -0,0 +1,4 @@
++void
++x1 (void)
++{
++}
+diff --git a/ld/testsuite/ld-plugin/pr23460b.c b/ld/testsuite/ld-plugin/pr23460b.c
+new file mode 100644
+index 0000000000..6c178fbc76
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/pr23460b.c
+@@ -0,0 +1,4 @@
++void
++x2 (void)
++{
++}
+diff --git a/ld/testsuite/ld-plugin/pr23460c.c b/ld/testsuite/ld-plugin/pr23460c.c
+new file mode 100644
+index 0000000000..99b23c5dcd
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/pr23460c.c
+@@ -0,0 +1,4 @@
++void
++x3 (void)
++{
++}
+diff --git a/ld/testsuite/ld-plugin/pr23460d.c b/ld/testsuite/ld-plugin/pr23460d.c
+new file mode 100644
+index 0000000000..432d39b39c
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/pr23460d.c
+@@ -0,0 +1,4 @@
++void
++x4 (void)
++{
++}
+diff --git a/ld/testsuite/ld-plugin/pr23460e.c b/ld/testsuite/ld-plugin/pr23460e.c
+new file mode 100644
+index 0000000000..2809011ee7
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/pr23460e.c
+@@ -0,0 +1,4 @@
++void
++x5 (void)
++{
++}
+diff --git a/ld/testsuite/ld-plugin/pr23460f.c b/ld/testsuite/ld-plugin/pr23460f.c
+new file mode 100644
+index 0000000000..e500bf5ae6
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/pr23460f.c
+@@ -0,0 +1,4 @@
++void
++x6 (void)
++{
++}
+-- 
+2.18.0
+

Copied: binutils/repos/testing-x86_64/PKGBUILD (from rev 331139, binutils/trunk/PKGBUILD)
===================================================================
--- testing-x86_64/PKGBUILD	                        (rev 0)
+++ testing-x86_64/PKGBUILD	2018-08-07 23:18:31 UTC (rev 331140)
@@ -0,0 +1,92 @@
+# $Id$
+# Maintainer:  Bartłomiej Piotrowski <bpiotrowski at archlinux.org>
+# Contributor: Allan McRae <allan at archlinux.org>
+
+# toolchain build order: linux-api-headers->glibc->binutils->gcc->binutils->glibc
+
+pkgname=binutils
+pkgver=2.31.1
+pkgrel=2
+pkgdesc='A set of programs to assemble and manipulate binary and object files'
+arch=(x86_64)
+url='http://www.gnu.org/software/binutils/'
+license=(GPL)
+groups=(base-devel)
+depends=(glibc zlib)
+checkdepends=(dejagnu bc)
+conflicts=(binutils-multilib)
+replaces=(binutils-multilib)
+options=(staticlibs !distcc !ccache)
+source=(https://ftp.gnu.org/gnu/binutils/binutils-$pkgver.tar.xz{,.sig}
+        0001-PR23428-x86-Add-a-GNU_PROPERTY_X86_ISA_1_USED-note-if-needed.patch
+        0002-PR23460-Close-resource-leaks-in-the-BFD-library-s-plugin-han.patch
+        0003-PR23460-Add-a-testcase-for-PR-binutils-23460.patch)
+validpgpkeys=(3A24BC1E8FB409FA9F14371813FCEF89DD9E3C4F)
+md5sums=('5b7c9d4ce96f507d95c1b9a255e52418'
+         'SKIP'
+         'f2d4f2aee9ec2e25210eb132acdcf1d9'
+         '496e7e2d71fe558b3b85cdc27fb4638e'
+         'dd2284134542efe8e38137f5c829a371')
+
+prepare() {
+  mkdir -p binutils-build
+
+  #cd binutils-gdb
+  cd binutils-$pkgver
+
+  # https://sourceware.org/bugzilla/show_bug.cgi?id=23428
+  patch -Np1 -i ../0001-PR23428-x86-Add-a-GNU_PROPERTY_X86_ISA_1_USED-note-if-needed.patch
+
+  # https://sourceware.org/bugzilla/show_bug.cgi?id=23460
+  patch -Np1 -i ../0002-PR23460-Close-resource-leaks-in-the-BFD-library-s-plugin-han.patch
+  patch -Np1 -i ../0003-PR23460-Add-a-testcase-for-PR-binutils-23460.patch
+
+  # hack! - libiberty configure tests for header files using "$CPP $CPPFLAGS"
+  sed -i "/ac_cpp=/s/\$CPPFLAGS/\$CPPFLAGS -O2/" libiberty/configure
+}
+
+build() {
+  cd binutils-build
+
+  "$srcdir/binutils-$pkgver/configure" \
+    --prefix=/usr \
+    --with-lib-path=/usr/lib:/usr/local/lib \
+    --with-bugurl=https://bugs.archlinux.org/ \
+    --enable-deterministic-archives \
+    --enable-gold \
+    --enable-ld=default \
+    --enable-lto \
+    --enable-plugins \
+    --enable-relro \
+    --enable-shared \
+    --enable-targets=x86_64-pep \
+    --enable-threads \
+    --disable-gdb \
+    --disable-werror \
+    --with-pic \
+    --with-system-zlib
+
+  make configure-host
+  make tooldir=/usr
+}
+
+check() {
+  cd binutils-build
+  
+  # unset LDFLAGS as testsuite makes assumptions about which ones are active
+  # ignore failures in gold testsuite...
+  make -k LDFLAGS="" check || true
+}
+
+package() {
+  cd binutils-build
+  make prefix="$pkgdir/usr" tooldir="$pkgdir/usr" install
+
+  # Remove unwanted files
+  rm -f "$pkgdir"/usr/share/man/man1/{dlltool,nlmconv,windres,windmc}*
+
+  # No shared linking to these files outside binutils
+  rm -f "$pkgdir"/usr/lib/lib{bfd,opcodes}.so
+  echo 'INPUT( /usr/lib/libbfd.a -liberty -lz -ldl )' > "$pkgdir/usr/lib/libbfd.so"
+  echo 'INPUT( /usr/lib/libopcodes.a -lbfd )' > "$pkgdir/usr/lib/libopcodes.so"
+}



More information about the arch-commits mailing list