1 |
From 1c611b40e6bfc8029bff7696814330b5bc0ee5c0 Mon Sep 17 00:00:00 2001 |
2 |
From: "H.J. Lu" <hjl.tools@gmail.com> |
3 |
Date: Mon, 26 Jul 2021 05:59:55 -0700 |
4 |
Subject: bfd: Close the file descriptor if there is no archive fd |
5 |
|
6 |
Close the file descriptor if there is no archive plugin file descriptor |
7 |
to avoid running out of file descriptors on thin archives with many |
8 |
archive members. |
9 |
|
10 |
bfd/ |
11 |
|
12 |
PR ld/28138 |
13 |
* plugin.c (bfd_plugin_close_file_descriptor): Close the file |
14 |
descriptor there is no archive plugin file descriptor. |
15 |
|
16 |
ld/ |
17 |
|
18 |
PR ld/28138 |
19 |
* testsuite/ld-plugin/lto.exp: Run tmpdir/pr28138 only for |
20 |
native build. |
21 |
|
22 |
PR ld/28138 |
23 |
* testsuite/ld-plugin/lto.exp: Run ld/28138 tests. |
24 |
* testsuite/ld-plugin/pr28138.c: New file. |
25 |
* testsuite/ld-plugin/pr28138-1.c: Likewise. |
26 |
* testsuite/ld-plugin/pr28138-2.c: Likewise. |
27 |
* testsuite/ld-plugin/pr28138-3.c: Likewise. |
28 |
* testsuite/ld-plugin/pr28138-4.c: Likewise. |
29 |
* testsuite/ld-plugin/pr28138-5.c: Likewise. |
30 |
* testsuite/ld-plugin/pr28138-6.c: Likewise. |
31 |
* testsuite/ld-plugin/pr28138-7.c: Likewise. |
32 |
|
33 |
(cherry picked from commit 5a98fb7513b559e20dfebdbaa2a471afda3b4742) |
34 |
(cherry picked from commit 7dc37e1e1209c80e0bab784df6b6bac335e836f2) |
35 |
--- |
36 |
bfd/plugin.c | 8 +++++++ |
37 |
ld/testsuite/ld-plugin/lto.exp | 34 ++++++++++++++++++++++++++++++ |
38 |
ld/testsuite/ld-plugin/pr28138-1.c | 6 ++++++ |
39 |
ld/testsuite/ld-plugin/pr28138-2.c | 6 ++++++ |
40 |
ld/testsuite/ld-plugin/pr28138-3.c | 6 ++++++ |
41 |
ld/testsuite/ld-plugin/pr28138-4.c | 6 ++++++ |
42 |
ld/testsuite/ld-plugin/pr28138-5.c | 6 ++++++ |
43 |
ld/testsuite/ld-plugin/pr28138-6.c | 6 ++++++ |
44 |
ld/testsuite/ld-plugin/pr28138-7.c | 6 ++++++ |
45 |
ld/testsuite/ld-plugin/pr28138.c | 20 ++++++++++++++++++ |
46 |
10 files changed, 104 insertions(+) |
47 |
create mode 100644 ld/testsuite/ld-plugin/pr28138-1.c |
48 |
create mode 100644 ld/testsuite/ld-plugin/pr28138-2.c |
49 |
create mode 100644 ld/testsuite/ld-plugin/pr28138-3.c |
50 |
create mode 100644 ld/testsuite/ld-plugin/pr28138-4.c |
51 |
create mode 100644 ld/testsuite/ld-plugin/pr28138-5.c |
52 |
create mode 100644 ld/testsuite/ld-plugin/pr28138-6.c |
53 |
create mode 100644 ld/testsuite/ld-plugin/pr28138-7.c |
54 |
create mode 100644 ld/testsuite/ld-plugin/pr28138.c |
55 |
|
56 |
diff --git a/bfd/plugin.c b/bfd/plugin.c |
57 |
index 6cfa2b66470..3bab8febe88 100644 |
58 |
--- a/bfd/plugin.c |
59 |
+++ b/bfd/plugin.c |
60 |
@@ -291,6 +291,14 @@ bfd_plugin_close_file_descriptor (bfd *abfd, int fd) |
61 |
&& !bfd_is_thin_archive (abfd->my_archive)) |
62 |
abfd = abfd->my_archive; |
63 |
|
64 |
+ /* Close the file descriptor if there is no archive plugin file |
65 |
+ descriptor. */ |
66 |
+ if (abfd->archive_plugin_fd == -1) |
67 |
+ { |
68 |
+ close (fd); |
69 |
+ return; |
70 |
+ } |
71 |
+ |
72 |
abfd->archive_plugin_fd_open_count--; |
73 |
/* Dup the archive plugin file descriptor for later use, which |
74 |
will be closed by _bfd_archive_close_and_cleanup. */ |
75 |
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp |
76 |
index def69e43ab3..999d911ce6a 100644 |
77 |
--- a/ld/testsuite/ld-plugin/lto.exp |
78 |
+++ b/ld/testsuite/ld-plugin/lto.exp |
79 |
@@ -687,6 +687,40 @@ if { [is_elf_format] && [check_lto_shared_available] } { |
80 |
} |
81 |
} |
82 |
|
83 |
+run_cc_link_tests [list \ |
84 |
+ [list \ |
85 |
+ "Build pr28138.a" \ |
86 |
+ "-T" "" \ |
87 |
+ {pr28138-1.c pr28138-2.c pr28138-3.c pr28138-4.c pr28138-5.c \ |
88 |
+ pr28138-6.c pr28138-7.c} {} "pr28138.a" \ |
89 |
+ ] \ |
90 |
+ [list \ |
91 |
+ "Build pr28138.o" \ |
92 |
+ "" "" \ |
93 |
+ {pr28138.c} {} \ |
94 |
+ ] \ |
95 |
+] |
96 |
+ |
97 |
+set exec_output [run_host_cmd "sh" \ |
98 |
+ "-c \"ulimit -n 20; \ |
99 |
+ $CC -Btmpdir/ld -o tmpdir/pr28138 \ |
100 |
+ tmpdir/pr28138.o tmpdir/pr28138.a\""] |
101 |
+set exec_output [prune_warnings $exec_output] |
102 |
+if [string match "" $exec_output] then { |
103 |
+ if { [isnative] } { |
104 |
+ set exec_output [run_host_cmd "tmpdir/pr28138" ""] |
105 |
+ if [string match "PASS" $exec_output] then { |
106 |
+ pass "PR ld/28138" |
107 |
+ } else { |
108 |
+ fail "PR ld/28138" |
109 |
+ } |
110 |
+ } else { |
111 |
+ pass "PR ld/28138" |
112 |
+ } |
113 |
+} else { |
114 |
+ fail "PR ld/28138" |
115 |
+} |
116 |
+ |
117 |
set testname "Build liblto-11.a" |
118 |
remote_file host delete "tmpdir/liblto-11.a" |
119 |
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"] |
120 |
diff --git a/ld/testsuite/ld-plugin/pr28138-1.c b/ld/testsuite/ld-plugin/pr28138-1.c |
121 |
new file mode 100644 |
122 |
index 00000000000..51d119e1642 |
123 |
--- /dev/null |
124 |
+++ b/ld/testsuite/ld-plugin/pr28138-1.c |
125 |
@@ -0,0 +1,6 @@ |
126 |
+extern int a0(void); |
127 |
+int |
128 |
+a1(void) |
129 |
+{ |
130 |
+ return 1 + a0(); |
131 |
+} |
132 |
diff --git a/ld/testsuite/ld-plugin/pr28138-2.c b/ld/testsuite/ld-plugin/pr28138-2.c |
133 |
new file mode 100644 |
134 |
index 00000000000..1120cd797e9 |
135 |
--- /dev/null |
136 |
+++ b/ld/testsuite/ld-plugin/pr28138-2.c |
137 |
@@ -0,0 +1,6 @@ |
138 |
+extern int a1(void); |
139 |
+int |
140 |
+a2(void) |
141 |
+{ |
142 |
+ return 1 + a1(); |
143 |
+} |
144 |
diff --git a/ld/testsuite/ld-plugin/pr28138-3.c b/ld/testsuite/ld-plugin/pr28138-3.c |
145 |
new file mode 100644 |
146 |
index 00000000000..ec464947ee6 |
147 |
--- /dev/null |
148 |
+++ b/ld/testsuite/ld-plugin/pr28138-3.c |
149 |
@@ -0,0 +1,6 @@ |
150 |
+extern int a2(void); |
151 |
+int |
152 |
+a3(void) |
153 |
+{ |
154 |
+ return 1 + a2(); |
155 |
+} |
156 |
diff --git a/ld/testsuite/ld-plugin/pr28138-4.c b/ld/testsuite/ld-plugin/pr28138-4.c |
157 |
new file mode 100644 |
158 |
index 00000000000..475701b2c5c |
159 |
--- /dev/null |
160 |
+++ b/ld/testsuite/ld-plugin/pr28138-4.c |
161 |
@@ -0,0 +1,6 @@ |
162 |
+extern int a3(void); |
163 |
+int |
164 |
+a4(void) |
165 |
+{ |
166 |
+ return 1 + a3(); |
167 |
+} |
168 |
diff --git a/ld/testsuite/ld-plugin/pr28138-5.c b/ld/testsuite/ld-plugin/pr28138-5.c |
169 |
new file mode 100644 |
170 |
index 00000000000..e24f86c363e |
171 |
--- /dev/null |
172 |
+++ b/ld/testsuite/ld-plugin/pr28138-5.c |
173 |
@@ -0,0 +1,6 @@ |
174 |
+extern int a4(void); |
175 |
+int |
176 |
+a5(void) |
177 |
+{ |
178 |
+ return 1 + a4(); |
179 |
+} |
180 |
diff --git a/ld/testsuite/ld-plugin/pr28138-6.c b/ld/testsuite/ld-plugin/pr28138-6.c |
181 |
new file mode 100644 |
182 |
index 00000000000..b5b938bdb21 |
183 |
--- /dev/null |
184 |
+++ b/ld/testsuite/ld-plugin/pr28138-6.c |
185 |
@@ -0,0 +1,6 @@ |
186 |
+extern int a5(void); |
187 |
+int |
188 |
+a6(void) |
189 |
+{ |
190 |
+ return 1 + a5(); |
191 |
+} |
192 |
diff --git a/ld/testsuite/ld-plugin/pr28138-7.c b/ld/testsuite/ld-plugin/pr28138-7.c |
193 |
new file mode 100644 |
194 |
index 00000000000..4ef75bf0f0c |
195 |
--- /dev/null |
196 |
+++ b/ld/testsuite/ld-plugin/pr28138-7.c |
197 |
@@ -0,0 +1,6 @@ |
198 |
+extern int a6(void); |
199 |
+int |
200 |
+a7(void) |
201 |
+{ |
202 |
+ return 1 + a6(); |
203 |
+} |
204 |
diff --git a/ld/testsuite/ld-plugin/pr28138.c b/ld/testsuite/ld-plugin/pr28138.c |
205 |
new file mode 100644 |
206 |
index 00000000000..68252c9f382 |
207 |
--- /dev/null |
208 |
+++ b/ld/testsuite/ld-plugin/pr28138.c |
209 |
@@ -0,0 +1,20 @@ |
210 |
+#include <stdio.h> |
211 |
+ |
212 |
+extern int a7(void); |
213 |
+ |
214 |
+int |
215 |
+a0(void) |
216 |
+{ |
217 |
+ return 0; |
218 |
+} |
219 |
+ |
220 |
+int |
221 |
+main() |
222 |
+{ |
223 |
+ if (a7() == 7) |
224 |
+ { |
225 |
+ printf ("PASS\n"); |
226 |
+ return 0; |
227 |
+ } |
228 |
+ return 1; |
229 |
+} |
230 |
-- |
231 |
2.32.0 |
232 |
|