fef86a9cb5aa138365f284cb8caae85de9e196d6
[openwrt/staging/chunkeey.git] / toolchain / binutils / patches / 2.37 / 600-Close_the_file_descriptor.patch
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
5
6 bfd: Close the file descriptor if there is no archive fd
7
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
10 archive members.
11
12 bfd/
13
14 PR ld/28138
15 * plugin.c (bfd_plugin_close_file_descriptor): Close the file
16 descriptor there is no archive plugin file descriptor.
17
18 ld/
19
20 PR ld/28138
21 * testsuite/ld-plugin/lto.exp: Run tmpdir/pr28138 only for
22 native build.
23
24 PR ld/28138
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.
34
35 (cherry picked from commit 5a98fb7513b559e20dfebdbaa2a471afda3b4742)
36 (cherry picked from commit 7dc37e1e1209c80e0bab784df6b6bac335e836f2)
37 ---
38
39 --- a/bfd/plugin.c
40 +++ b/bfd/plugin.c
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;
44
45 + /* Close the file descriptor if there is no archive plugin file
46 + descriptor. */
47 + if (abfd->archive_plugin_fd == -1)
48 + {
49 + close (fd);
50 + return;
51 + }
52 +
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
59 }
60 }
61
62 +run_cc_link_tests [list \
63 + [list \
64 + "Build pr28138.a" \
65 + "-T" "" \
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" \
68 + ] \
69 + [list \
70 + "Build pr28138.o" \
71 + "" "" \
72 + {pr28138.c} {} \
73 + ] \
74 +]
75 +
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 {
82 + if { [isnative] } {
83 + set exec_output [run_host_cmd "tmpdir/pr28138" ""]
84 + if [string match "PASS" $exec_output] then {
85 + pass "PR ld/28138"
86 + } else {
87 + fail "PR ld/28138"
88 + }
89 + } else {
90 + pass "PR ld/28138"
91 + }
92 +} else {
93 + fail "PR ld/28138"
94 +}
95 +
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"]
99 --- /dev/null
100 +++ b/ld/testsuite/ld-plugin/pr28138-1.c
101 @@ -0,0 +1,6 @@
102 +extern int a0(void);
103 +int
104 +a1(void)
105 +{
106 + return 1 + a0();
107 +}
108 --- /dev/null
109 +++ b/ld/testsuite/ld-plugin/pr28138-2.c
110 @@ -0,0 +1,6 @@
111 +extern int a1(void);
112 +int
113 +a2(void)
114 +{
115 + return 1 + a1();
116 +}
117 --- /dev/null
118 +++ b/ld/testsuite/ld-plugin/pr28138-3.c
119 @@ -0,0 +1,6 @@
120 +extern int a2(void);
121 +int
122 +a3(void)
123 +{
124 + return 1 + a2();
125 +}
126 --- /dev/null
127 +++ b/ld/testsuite/ld-plugin/pr28138-4.c
128 @@ -0,0 +1,6 @@
129 +extern int a3(void);
130 +int
131 +a4(void)
132 +{
133 + return 1 + a3();
134 +}
135 --- /dev/null
136 +++ b/ld/testsuite/ld-plugin/pr28138-5.c
137 @@ -0,0 +1,6 @@
138 +extern int a4(void);
139 +int
140 +a5(void)
141 +{
142 + return 1 + a4();
143 +}
144 --- /dev/null
145 +++ b/ld/testsuite/ld-plugin/pr28138-6.c
146 @@ -0,0 +1,6 @@
147 +extern int a5(void);
148 +int
149 +a6(void)
150 +{
151 + return 1 + a5();
152 +}
153 --- /dev/null
154 +++ b/ld/testsuite/ld-plugin/pr28138-7.c
155 @@ -0,0 +1,6 @@
156 +extern int a6(void);
157 +int
158 +a7(void)
159 +{
160 + return 1 + a6();
161 +}
162 --- /dev/null
163 +++ b/ld/testsuite/ld-plugin/pr28138.c
164 @@ -0,0 +1,20 @@
165 +#include <stdio.h>
166 +
167 +extern int a7(void);
168 +
169 +int
170 +a0(void)
171 +{
172 + return 0;
173 +}
174 +
175 +int
176 +main()
177 +{
178 + if (a7() == 7)
179 + {
180 + printf ("PASS\n");
181 + return 0;
182 + }
183 + return 1;
184 +}