1 From: H.J. Lu <hjl.tools@gmail.com>
2 Date: Mon, 26 Jul 2021 12:59:55 +0000 (-0700)
3 Subject: bfd: Close the file descriptor if there is no archive fd
4 X-Git-Url: https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff_plain;h=1c611b40e6bfc8029bff7696814330b5bc0ee5c0
6 bfd: Close the file descriptor if there is no archive fd
8 Close the file descriptor if there is no archive plugin file descriptor
9 to avoid running out of file descriptors on thin archives with many
15 * plugin.c (bfd_plugin_close_file_descriptor): Close the file
16 descriptor there is no archive plugin file descriptor.
21 * testsuite/ld-plugin/lto.exp: Run tmpdir/pr28138 only for
25 * testsuite/ld-plugin/lto.exp: Run ld/28138 tests.
26 * testsuite/ld-plugin/pr28138.c: New file.
27 * testsuite/ld-plugin/pr28138-1.c: Likewise.
28 * testsuite/ld-plugin/pr28138-2.c: Likewise.
29 * testsuite/ld-plugin/pr28138-3.c: Likewise.
30 * testsuite/ld-plugin/pr28138-4.c: Likewise.
31 * testsuite/ld-plugin/pr28138-5.c: Likewise.
32 * testsuite/ld-plugin/pr28138-6.c: Likewise.
33 * testsuite/ld-plugin/pr28138-7.c: Likewise.
35 (cherry picked from commit 5a98fb7513b559e20dfebdbaa2a471afda3b4742)
36 (cherry picked from commit 7dc37e1e1209c80e0bab784df6b6bac335e836f2)
41 @@ -291,6 +291,14 @@ bfd_plugin_close_file_descriptor (bfd *a
42 && !bfd_is_thin_archive (abfd->my_archive))
43 abfd = abfd->my_archive;
45 + /* Close the file descriptor if there is no archive plugin file
47 + if (abfd->archive_plugin_fd == -1)
53 abfd->archive_plugin_fd_open_count--;
54 /* Dup the archive plugin file descriptor for later use, which
55 will be closed by _bfd_archive_close_and_cleanup. */
56 --- a/ld/testsuite/ld-plugin/lto.exp
57 +++ b/ld/testsuite/ld-plugin/lto.exp
58 @@ -687,6 +687,40 @@ if { [is_elf_format] && [check_lto_share
62 +run_cc_link_tests [list \
66 + {pr28138-1.c pr28138-2.c pr28138-3.c pr28138-4.c pr28138-5.c \
67 + pr28138-6.c pr28138-7.c} {} "pr28138.a" \
76 +set exec_output [run_host_cmd "sh" \
77 + "-c \"ulimit -n 20; \
78 + $CC -Btmpdir/ld -o tmpdir/pr28138 \
79 + tmpdir/pr28138.o tmpdir/pr28138.a\""]
80 +set exec_output [prune_warnings $exec_output]
81 +if [string match "" $exec_output] then {
83 + set exec_output [run_host_cmd "tmpdir/pr28138" ""]
84 + if [string match "PASS" $exec_output] then {
96 set testname "Build liblto-11.a"
97 remote_file host delete "tmpdir/liblto-11.a"
98 set catch_output [run_host_cmd "$ar" "rc $plug_opt tmpdir/liblto-11.a tmpdir/lto-11a.o tmpdir/lto-11b.o tmpdir/lto-11c.o"]
100 +++ b/ld/testsuite/ld-plugin/pr28138-1.c
102 +extern int a0(void);
109 +++ b/ld/testsuite/ld-plugin/pr28138-2.c
111 +extern int a1(void);
118 +++ b/ld/testsuite/ld-plugin/pr28138-3.c
120 +extern int a2(void);
127 +++ b/ld/testsuite/ld-plugin/pr28138-4.c
129 +extern int a3(void);
136 +++ b/ld/testsuite/ld-plugin/pr28138-5.c
138 +extern int a4(void);
145 +++ b/ld/testsuite/ld-plugin/pr28138-6.c
147 +extern int a5(void);
154 +++ b/ld/testsuite/ld-plugin/pr28138-7.c
156 +extern int a6(void);
163 +++ b/ld/testsuite/ld-plugin/pr28138.c
167 +extern int a7(void);