aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2021-05-19 11:53:23 +0100
committerNick Clifton <nickc@redhat.com>2021-05-19 11:53:23 +0100
commit83b0a6865c081de2f6e8f56870d832b9fb65edde (patch)
tree4dd178e13eab97a4d1c13d198fdb412121f9ed3f /bfd
parentb534617fd56d260d8d6c6c40124390ce72af476a (diff)
downloadfsf-binutils-gdb-83b0a6865c081de2f6e8f56870d832b9fb65edde.zip
fsf-binutils-gdb-83b0a6865c081de2f6e8f56870d832b9fb65edde.tar.gz
fsf-binutils-gdb-83b0a6865c081de2f6e8f56870d832b9fb65edde.tar.bz2
Warn when the plugin interface runs out of file descriptors.
* plugin.c (bfd_plugin_open_input): Inform the user if the limit on the number of open files is reached. If possible, try to increase this limit before failing.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog6
-rw-r--r--bfd/plugin.c30
2 files changed, 35 insertions, 1 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index b399aef..a389fdf 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2021-05-19 Nick Clifton <nickc@redhat.com>
+
+ * plugin.c (bfd_plugin_open_input): Inform the user if the limit
+ on the number of open files is reached. If possible, try to
+ increase this limit before failing.
+
2021-05-14 Nelson Chu <nelson.chu@sifive.com>
* elfnn-riscv.c (riscv_resolve_pcrel_lo_relocs): Check the values
diff --git a/bfd/plugin.c b/bfd/plugin.c
index c4f2be8..1fee4d0 100644
--- a/bfd/plugin.c
+++ b/bfd/plugin.c
@@ -209,7 +209,35 @@ bfd_plugin_open_input (bfd *ibfd, struct ld_plugin_input_file *file)
the same underlying file descriptor. */
file->fd = open (file->name, O_RDONLY | O_BINARY);
if (file->fd < 0)
- return 0;
+ {
+#ifndef EMFILE
+ return 0;
+#else
+ if (errno != EMFILE)
+ return 0;
+
+#ifdef HAVE_GETRLIMIT
+ struct rlimit lim;
+
+ /* Complicated links involving lots of files and/or large archives
+ can exhaust the number of file descriptors available to us.
+ If possible, try to allocate more descriptors. */
+ if (getrlimit (RLIMIT_NOFILE, & lim) == 0
+ && lim.rlim_cur < lim.rlim_max)
+ {
+ lim.rlim_cur = lim.rlim_max;
+ if (setrlimit (RLIMIT_NOFILE, &lim) == 0)
+ file->fd = open (file->name, O_RDONLY | O_BINARY);
+ }
+
+ if (file->fd < 0)
+#endif
+ {
+ _bfd_error_handler (_("plugin framework: out of file descriptors. Try using fewer objects/archives\n"));
+ return 0;
+ }
+#endif
+ }
if (iobfd == ibfd)
{