diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2021-07-02 13:42:32 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2021-07-05 08:51:35 -0700 |
commit | 918172470430ea6fa082c941e6789add88331197 (patch) | |
tree | d32fe8758c189052469f5b029bef5ebc3fc01a51 /ld/plugin.c | |
parent | c919d6be44913ed52d91c203e87e529ee17de805 (diff) | |
download | gdb-918172470430ea6fa082c941e6789add88331197.zip gdb-918172470430ea6fa082c941e6789add88331197.tar.gz gdb-918172470430ea6fa082c941e6789add88331197.tar.bz2 |
ld: Cache and reuse the IR archive file descriptor
Linker plugin_object_p opens the IR archive for each IR archive member.
For GCC plugin, plugin_object_p closes the archive file descriptor. But
for LLVM plugin, the archive file descriptor remains open. If there are
3000 IR archive members, there are 3000 file descriptors for them. We
can run out of file descriptors petty easily.
1. Add archive_plugin_fd and archive_plugin_fd_open_count to bfd so that
we can cache and reuse the IR archive file descriptor for all IR archive
members in the archive.
2. Add bfd_plugin_close_file_descriptor to properly close the IR archive
file descriptor.
bfd/
PR ld/28040
* archive.c (_bfd_archive_close_and_cleanup): Close the archive
plugin file descriptor if needed.
* bfd.c (bfd): Add archive_plugin_fd and
archive_plugin_fd_open_count.
* opncls.c (_bfd_new_bfd): Initialize to -1.
* plugin.c (bfd_plugin_open_input): Cache and reuse the archive
plugin file descriptor.
(bfd_plugin_close_file_descriptor): New function.
(try_claim): Call bfd_plugin_close_file_descriptor.
* plugin.h (bfd_plugin_close_file_descriptor): New.
* bfd-in2.h: Regenerated.
ld/
PR ld/28040
* plugin.c (plugin_input_file): Add ibfd.
(release_plugin_file_descriptor): New function.
(release_input_file): Call release_plugin_file_descriptor to
close input->fd.
(plugin_object_p): Call release_plugin_file_descriptor to close
input->fd. Also call release_plugin_file_descriptor if not
claimed.
* testsuite/config/default.exp (RANLIB): New.
* testsuite/ld-plugin/lto.exp: Run ranlib test.
Diffstat (limited to 'ld/plugin.c')
-rw-r--r-- | ld/plugin.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/ld/plugin.c b/ld/plugin.c index 98a83bc..bb369f4 100644 --- a/ld/plugin.c +++ b/ld/plugin.c @@ -103,6 +103,7 @@ typedef struct view_buffer typedef struct plugin_input_file { bfd *abfd; + bfd *ibfd; view_buffer_t view_buffer; char *name; int fd; @@ -605,17 +606,25 @@ get_view (const void *handle, const void **viewp) return LDPS_OK; } +/* Release plugin file descriptor. */ + +static void +release_plugin_file_descriptor (plugin_input_file_t *input) +{ + if (input->fd != -1) + { + bfd_plugin_close_file_descriptor (input->ibfd, input->fd); + input->fd = -1; + } +} + /* Release the input file. */ static enum ld_plugin_status release_input_file (const void *handle) { plugin_input_file_t *input = (plugin_input_file_t *) handle; ASSERT (called_plugin); - if (input->fd != -1) - { - close (input->fd); - input->fd = -1; - } + release_plugin_file_descriptor (input); return LDPS_OK; } @@ -1211,6 +1220,7 @@ plugin_object_p (bfd *ibfd) file.handle = input; input->abfd = abfd; + input->ibfd = ibfd; input->view_buffer.addr = NULL; input->view_buffer.filesize = 0; input->view_buffer.offset = 0; @@ -1226,7 +1236,8 @@ plugin_object_p (bfd *ibfd) einfo (_("%F%P: %s: plugin reported error claiming file\n"), plugin_error_plugin ()); - if (input->fd != -1 && !bfd_plugin_target_p (ibfd->xvec)) + if (input->fd != -1 + && (!claimed || !bfd_plugin_target_p (ibfd->xvec))) { /* FIXME: fd belongs to us, not the plugin. GCC plugin, which doesn't need fd after plugin_call_claim_file, doesn't use @@ -1236,8 +1247,7 @@ plugin_object_p (bfd *ibfd) release_input_file after it is done, uses BFD plugin target vector. This scheme doesn't work when a plugin needs fd and doesn't use BFD plugin target vector neither. */ - close (input->fd); - input->fd = -1; + release_plugin_file_descriptor (input); } if (claimed) |