mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-21 02:24:17 +08:00
Update plugin_maybe_claim
This patch removes the argument of pointer to struct ld_plugin_input_file. This is the first step to extract a plugin_object_p out of plugin_maybe_claim for BFD. * plugin.c: Include "libbfd.h". (plugin_strdup): New. (plugin_maybe_claim): Remove the argument of pointer to struct ld_plugin_input_file. Open and handle input entry. * plugin.h (plugin_maybe_claim): Updated. * ldfile.c (ldfile_try_open_bfd): Call plugin_maybe_claim directly without passing a pointer to struct ld_plugin_input_file. * ldmain.c: Don't include "libbfd.h". (add_archive_element): Call plugin_maybe_claim directly without passing a pointer to struct ld_plugin_input_file.
This commit is contained in:
13
ld/ChangeLog
13
ld/ChangeLog
@ -1,3 +1,16 @@
|
|||||||
|
2015-02-07 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
|
* plugin.c: Include "libbfd.h".
|
||||||
|
(plugin_strdup): New.
|
||||||
|
(plugin_maybe_claim): Remove the argument of pointer to struct
|
||||||
|
ld_plugin_input_file. Open and handle input entry.
|
||||||
|
* plugin.h (plugin_maybe_claim): Updated.
|
||||||
|
* ldfile.c (ldfile_try_open_bfd): Call plugin_maybe_claim directly
|
||||||
|
without passing a pointer to struct ld_plugin_input_file.
|
||||||
|
* ldmain.c: Don't include "libbfd.h".
|
||||||
|
(add_archive_element): Call plugin_maybe_claim directly without
|
||||||
|
passing a pointer to struct ld_plugin_input_file.
|
||||||
|
|
||||||
2015-02-06 H.J. Lu <hongjiu.lu@intel.com>
|
2015-02-06 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
* ld.texinfo: Document -z text, -z notext and -z textoff.
|
* ld.texinfo: Document -z text, -z notext and -z textoff.
|
||||||
|
14
ld/ldfile.c
14
ld/ldfile.c
@ -304,19 +304,7 @@ success:
|
|||||||
if (bfd_check_format (entry->the_bfd, bfd_object)
|
if (bfd_check_format (entry->the_bfd, bfd_object)
|
||||||
&& link_info.lto_plugin_active
|
&& link_info.lto_plugin_active
|
||||||
&& !no_more_claiming)
|
&& !no_more_claiming)
|
||||||
{
|
plugin_maybe_claim (entry);
|
||||||
int fd = open (attempt, O_RDONLY | O_BINARY);
|
|
||||||
if (fd >= 0)
|
|
||||||
{
|
|
||||||
struct ld_plugin_input_file file;
|
|
||||||
|
|
||||||
file.name = attempt;
|
|
||||||
file.offset = 0;
|
|
||||||
file.filesize = lseek (fd, 0, SEEK_END);
|
|
||||||
file.fd = fd;
|
|
||||||
plugin_maybe_claim (&file, entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* ENABLE_PLUGINS */
|
#endif /* ENABLE_PLUGINS */
|
||||||
|
|
||||||
/* It opened OK, the format checked out, and the plugins have had
|
/* It opened OK, the format checked out, and the plugins have had
|
||||||
|
19
ld/ldmain.c
19
ld/ldmain.c
@ -41,7 +41,6 @@
|
|||||||
#ifdef ENABLE_PLUGINS
|
#ifdef ENABLE_PLUGINS
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
#include "plugin-api.h"
|
#include "plugin-api.h"
|
||||||
#include "libbfd.h"
|
|
||||||
#endif /* ENABLE_PLUGINS */
|
#endif /* ENABLE_PLUGINS */
|
||||||
|
|
||||||
/* Somewhere above, sys/stat.h got included. */
|
/* Somewhere above, sys/stat.h got included. */
|
||||||
@ -793,29 +792,13 @@ add_archive_element (struct bfd_link_info *info,
|
|||||||
if (link_info.lto_plugin_active && !no_more_claiming)
|
if (link_info.lto_plugin_active && !no_more_claiming)
|
||||||
{
|
{
|
||||||
/* We must offer this archive member to the plugins to claim. */
|
/* We must offer this archive member to the plugins to claim. */
|
||||||
const char *filename = (bfd_my_archive (abfd) != NULL
|
plugin_maybe_claim (input);
|
||||||
? bfd_my_archive (abfd)->filename : abfd->filename);
|
|
||||||
int fd = open (filename, O_RDONLY | O_BINARY);
|
|
||||||
if (fd >= 0)
|
|
||||||
{
|
|
||||||
struct ld_plugin_input_file file;
|
|
||||||
|
|
||||||
/* Offset and filesize must refer to the individual archive
|
|
||||||
member, not the whole file, and must exclude the header.
|
|
||||||
Fortunately for us, that is how the data is stored in the
|
|
||||||
origin field of the bfd and in the arelt_data. */
|
|
||||||
file.name = filename;
|
|
||||||
file.offset = abfd->origin;
|
|
||||||
file.filesize = arelt_size (abfd);
|
|
||||||
file.fd = fd;
|
|
||||||
plugin_maybe_claim (&file, input);
|
|
||||||
if (input->flags.claimed)
|
if (input->flags.claimed)
|
||||||
{
|
{
|
||||||
input->flags.claim_archive = TRUE;
|
input->flags.claim_archive = TRUE;
|
||||||
*subsbfd = input->the_bfd;
|
*subsbfd = input->the_bfd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif /* ENABLE_PLUGINS */
|
#endif /* ENABLE_PLUGINS */
|
||||||
|
|
||||||
ldlang_add_file (input);
|
ldlang_add_file (input);
|
||||||
|
85
ld/plugin.c
85
ld/plugin.c
@ -21,6 +21,7 @@
|
|||||||
#include "sysdep.h"
|
#include "sysdep.h"
|
||||||
#include "libiberty.h"
|
#include "libiberty.h"
|
||||||
#include "bfd.h"
|
#include "bfd.h"
|
||||||
|
#include "libbfd.h"
|
||||||
#include "bfdlink.h"
|
#include "bfdlink.h"
|
||||||
#include "bfdver.h"
|
#include "bfdver.h"
|
||||||
#include "ld.h"
|
#include "ld.h"
|
||||||
@ -980,41 +981,83 @@ plugin_call_claim_file (const struct ld_plugin_input_file *file, int *claimed)
|
|||||||
return plugin_error_p () ? -1 : 0;
|
return plugin_error_p () ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Duplicates a character string with memory attached to ABFD. */
|
||||||
|
|
||||||
|
static char *
|
||||||
|
plugin_strdup (bfd *abfd, const char *str)
|
||||||
|
{
|
||||||
|
size_t strlength;
|
||||||
|
char *copy;
|
||||||
|
strlength = strlen (str) + 1;
|
||||||
|
copy = bfd_alloc (abfd, strlength);
|
||||||
|
if (copy == NULL)
|
||||||
|
einfo (_("%P%F: plugin_strdup failed to allocate memory: %s\n"),
|
||||||
|
bfd_get_error ());
|
||||||
|
memcpy (copy, str, strlength);
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
plugin_maybe_claim (struct ld_plugin_input_file *file,
|
plugin_maybe_claim (lang_input_statement_type *entry)
|
||||||
lang_input_statement_type *entry)
|
|
||||||
{
|
{
|
||||||
int claimed = 0;
|
int claimed = 0;
|
||||||
plugin_input_file_t *input;
|
plugin_input_file_t *input;
|
||||||
size_t namelength;
|
off_t offset, filesize;
|
||||||
|
struct ld_plugin_input_file file;
|
||||||
|
bfd *abfd;
|
||||||
|
bfd *ibfd = entry->the_bfd;
|
||||||
|
bfd_boolean inarchive = bfd_my_archive (ibfd) != NULL;
|
||||||
|
const char *name
|
||||||
|
= inarchive ? bfd_my_archive (ibfd)->filename : ibfd->filename;
|
||||||
|
int fd = open (name, O_RDONLY | O_BINARY);
|
||||||
|
|
||||||
|
if (fd < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
/* We create a dummy BFD, initially empty, to house whatever symbols
|
/* We create a dummy BFD, initially empty, to house whatever symbols
|
||||||
the plugin may want to add. */
|
the plugin may want to add. */
|
||||||
bfd *abfd = plugin_get_ir_dummy_bfd (entry->the_bfd->filename,
|
abfd = plugin_get_ir_dummy_bfd (ibfd->filename, ibfd);
|
||||||
entry->the_bfd);
|
|
||||||
|
|
||||||
input = bfd_alloc (abfd, sizeof (*input));
|
input = bfd_alloc (abfd, sizeof (*input));
|
||||||
if (input == NULL)
|
if (input == NULL)
|
||||||
einfo (_("%P%F: plugin failed to allocate memory for input: %s\n"),
|
einfo (_("%P%F: plugin failed to allocate memory for input: %s\n"),
|
||||||
bfd_get_error ());
|
bfd_get_error ());
|
||||||
|
|
||||||
|
if (inarchive)
|
||||||
|
{
|
||||||
|
/* Offset and filesize must refer to the individual archive
|
||||||
|
member, not the whole file, and must exclude the header.
|
||||||
|
Fortunately for us, that is how the data is stored in the
|
||||||
|
origin field of the bfd and in the arelt_data. */
|
||||||
|
offset = ibfd->origin;
|
||||||
|
filesize = arelt_size (ibfd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
offset = 0;
|
||||||
|
filesize = lseek (fd, 0, SEEK_END);
|
||||||
|
|
||||||
|
/* We must copy filename attached to ibfd if it is not an archive
|
||||||
|
member since it may be freed by bfd_close below. */
|
||||||
|
name = plugin_strdup (abfd, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
file.name = name;
|
||||||
|
file.offset = offset;
|
||||||
|
file.filesize = filesize;
|
||||||
|
file.fd = fd;
|
||||||
|
file.handle = input;
|
||||||
|
|
||||||
input->abfd = abfd;
|
input->abfd = abfd;
|
||||||
input->view_buffer.addr = NULL;
|
input->view_buffer.addr = NULL;
|
||||||
input->view_buffer.filesize = 0;
|
input->view_buffer.filesize = 0;
|
||||||
input->view_buffer.offset = 0;
|
input->view_buffer.offset = 0;
|
||||||
input->fd = file->fd;
|
input->fd = fd;
|
||||||
input->offset = file->offset;
|
input->offset = offset;
|
||||||
input->filesize = file->filesize;
|
input->filesize = filesize;
|
||||||
namelength = strlen (entry->the_bfd->filename) + 1;
|
input->name = plugin_strdup (abfd, ibfd->filename);
|
||||||
input->name = bfd_alloc (abfd, namelength);
|
|
||||||
if (input->name == NULL)
|
|
||||||
einfo (_("%P%F: plugin failed to allocate memory for input filename: %s\n"),
|
|
||||||
bfd_get_error ());
|
|
||||||
memcpy (input->name, entry->the_bfd->filename, namelength);
|
|
||||||
|
|
||||||
file->handle = input;
|
if (plugin_call_claim_file (&file, &claimed))
|
||||||
|
|
||||||
if (plugin_call_claim_file (file, &claimed))
|
|
||||||
einfo (_("%P%F: %s: plugin reported error claiming file\n"),
|
einfo (_("%P%F: %s: plugin reported error claiming file\n"),
|
||||||
plugin_error_plugin ());
|
plugin_error_plugin ());
|
||||||
|
|
||||||
@ -1028,7 +1071,7 @@ plugin_maybe_claim (struct ld_plugin_input_file *file,
|
|||||||
calls release_input_file after it is done, is stored in
|
calls release_input_file after it is done, is stored in
|
||||||
non-bfd_object file. This scheme doesn't work when a plugin
|
non-bfd_object file. This scheme doesn't work when a plugin
|
||||||
needs fd and its IR is stored in bfd_object file. */
|
needs fd and its IR is stored in bfd_object file. */
|
||||||
close (file->fd);
|
close (fd);
|
||||||
input->fd = -1;
|
input->fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1038,11 +1081,11 @@ plugin_maybe_claim (struct ld_plugin_input_file *file,
|
|||||||
|
|
||||||
/* BFD archive handling caches elements so we can't call
|
/* BFD archive handling caches elements so we can't call
|
||||||
bfd_close for archives. */
|
bfd_close for archives. */
|
||||||
if (entry->the_bfd->my_archive == NULL)
|
if (!inarchive)
|
||||||
bfd_close (entry->the_bfd);
|
bfd_close (ibfd);
|
||||||
|
bfd_make_readable (abfd);
|
||||||
entry->the_bfd = abfd;
|
entry->the_bfd = abfd;
|
||||||
entry->flags.claimed = TRUE;
|
entry->flags.claimed = TRUE;
|
||||||
bfd_make_readable (entry->the_bfd);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -46,8 +46,7 @@ extern void plugin_load_plugins (void);
|
|||||||
extern const char *plugin_error_plugin (void);
|
extern const char *plugin_error_plugin (void);
|
||||||
|
|
||||||
/* Call 'claim file' hook for all plugins. */
|
/* Call 'claim file' hook for all plugins. */
|
||||||
extern void plugin_maybe_claim (struct ld_plugin_input_file *,
|
extern void plugin_maybe_claim (lang_input_statement_type *);
|
||||||
lang_input_statement_type *);
|
|
||||||
|
|
||||||
/* Call 'all symbols read' hook for all plugins. */
|
/* Call 'all symbols read' hook for all plugins. */
|
||||||
extern int plugin_call_all_symbols_read (void);
|
extern int plugin_call_all_symbols_read (void);
|
||||||
|
Reference in New Issue
Block a user