aboutsummaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
Diffstat (limited to 'binutils')
-rw-r--r--binutils/MAINTAINERS1
-rw-r--r--binutils/doc/binutils.texi21
-rw-r--r--binutils/nm.c5
-rw-r--r--binutils/objcopy.c115
-rw-r--r--binutils/resbin.c10
-rw-r--r--binutils/testsuite/binutils-all/objcopy.exp8
6 files changed, 124 insertions, 36 deletions
diff --git a/binutils/MAINTAINERS b/binutils/MAINTAINERS
index 643a604..993a36e 100644
--- a/binutils/MAINTAINERS
+++ b/binutils/MAINTAINERS
@@ -63,7 +63,6 @@ maintainer. The first maintainer is free to devolve that
responsibility among the other maintainers.
AARCH64 Richard Earnshaw <rearnsha@arm.com>
- AARCH64 Marcus Shawcroft <marcus.shawcroft@arm.com>
ARC Claudiu Zissulescu <claziss@gmail.com>
ARM Nick Clifton <nickc@redhat.com>
ARM Richard Earnshaw <rearnsha@arm.com>
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index 7f041d9..d094f7d 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -3566,6 +3566,7 @@ strip [@option{-F} @var{bfdname} |@option{--target=}@var{bfdname}]
[@option{--keep-section-symbols}]
[@option{--keep-file-symbols}]
[@option{--only-keep-debug}]
+ [@option{--plugin} @var{name}]
[@option{-v} |@option{--verbose}] [@option{-V}|@option{--version}]
[@option{--help}] [@option{--info}]
@var{objfile}@dots{}
@@ -3825,6 +3826,26 @@ currently only supports the presence of one filename containing
debugging information, not multiple filenames on a one-per-object-file
basis.
+@item --plugin @var{name}
+@cindex plugins
+Load the plugin called @var{name} to add support for extra target
+types. This option is only available if the toolchain has been built
+with plugin support enabled.
+
+If @option{--plugin} is not provided, but plugin support has been
+enabled then @command{strip} iterates over the files in
+@file{$@{libdir@}/bfd-plugins} in alphabetic order and the first
+plugin that claims the object in question is used.
+
+Please note that this plugin search directory is @emph{not} the one
+used by @command{ld}'s @option{-plugin} option. In order to make
+@command{strip} use the linker plugin it must be copied into the
+@file{$@{libdir@}/bfd-plugins} directory. For GCC based compilations
+the linker plugin is called @file{liblto_plugin.so.0.0.0}. For Clang
+based compilations it is called @file{LLVMgold.so}. The GCC plugin
+is always backwards compatible with earlier versions, so it is
+sufficient to just copy the newest one.
+
@item -V
@itemx --version
Show the version number for @command{strip}.
diff --git a/binutils/nm.c b/binutils/nm.c
index 7ef5d61..a5d5631 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -801,10 +801,7 @@ filter_symbols (bfd *abfd, bool is_dynamic, void *minisyms,
if (sym == NULL)
continue;
- if (sym->name != NULL
- && sym->name[0] == '_'
- && sym->name[1] == '_'
- && strcmp (sym->name + (sym->name[2] == '_'), "__gnu_lto_slim") == 0
+ if (bfd_lto_slim_symbol_p (abfd, sym->name)
&& report_plugin_err)
{
report_plugin_err = false;
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 31933e1..a973789 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -30,6 +30,8 @@
#include "coff/internal.h"
#include "libcoff.h"
#include "safe-ctype.h"
+#include "plugin-api.h"
+#include "plugin.h"
/* FIXME: See bfd/peXXigen.c for why we include an architecture specific
header in generic PE code. */
@@ -165,6 +167,11 @@ static struct section_list *change_sections;
/* TRUE if some sections are to be removed. */
static bool sections_removed;
+#if BFD_SUPPORTS_PLUGINS
+/* TRUE if all GCC LTO sections are to be removed. */
+static bool lto_sections_removed;
+#endif
+
/* TRUE if only some sections are to be copied. */
static bool sections_copied;
@@ -359,6 +366,7 @@ enum command_line_switch
OPTION_RENAME_SECTION,
OPTION_REVERSE_BYTES,
OPTION_PE_SECTION_ALIGNMENT,
+ OPTION_PLUGIN,
OPTION_SET_SECTION_FLAGS,
OPTION_SET_SECTION_ALIGNMENT,
OPTION_SET_START,
@@ -402,6 +410,7 @@ static struct option strip_options[] =
{"output-file", required_argument, 0, 'o'},
{"output-format", required_argument, 0, 'O'}, /* Obsolete */
{"output-target", required_argument, 0, 'O'},
+ {"plugin", required_argument, 0, OPTION_PLUGIN},
{"preserve-dates", no_argument, 0, 'p'},
{"remove-section", required_argument, 0, 'R'},
{"remove-relocations", required_argument, 0, OPTION_REMOVE_RELOCS},
@@ -758,6 +767,10 @@ strip_usage (FILE *stream, int exit_status)
--info List object formats & architectures supported\n\
-o <file> Place stripped output into <file>\n\
"));
+#if BFD_SUPPORTS_PLUGINS
+ fprintf (stream, _("\
+ --plugin NAME Load the specified plugin\n"));
+#endif
list_supported_targets (program_name, stream);
if (REPORT_BUGS_TO[0] && exit_status == 0)
@@ -1916,20 +1929,11 @@ add_redefine_syms_file (const char *filename)
Returns TRUE upon success, FALSE otherwise. */
static bool
-copy_unknown_object (bfd *ibfd, bfd *obfd)
+copy_unknown_file (bfd *ibfd, bfd *obfd, off_t size, unsigned int mode)
{
char *cbuf;
bfd_size_type tocopy;
- off_t size;
- struct stat buf;
- if (bfd_stat_arch_elt (ibfd, &buf) != 0)
- {
- bfd_nonfatal_message (NULL, ibfd, NULL, NULL);
- return false;
- }
-
- size = buf.st_size;
if (size < 0)
{
non_fatal (_("stat returns negative size for `%s'"),
@@ -1974,11 +1978,31 @@ copy_unknown_object (bfd *ibfd, bfd *obfd)
/* We should at least to be able to read it back when copying an
unknown object in an archive. */
- chmod (bfd_get_filename (obfd), buf.st_mode | S_IRUSR);
+ chmod (bfd_get_filename (obfd), mode | S_IRUSR);
free (cbuf);
return true;
}
+/* Copy unknown object file archive member IBFD onto OBFD.
+ Returns TRUE upon success, FALSE otherwise. */
+
+static bool
+copy_unknown_object (bfd *ibfd, bfd *obfd)
+{
+ struct stat buf;
+
+ if (bfd_stat_arch_elt (ibfd, &buf) != 0)
+ {
+ bfd_nonfatal_message (NULL, ibfd, NULL, NULL);
+ return false;
+ }
+
+ if (!copy_unknown_file (ibfd, obfd, buf.st_size, buf.st_mode))
+ return false;
+
+ return true;
+}
+
typedef struct objcopy_internal_note
{
Elf_Internal_Note note;
@@ -3744,6 +3768,12 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
goto cleanup_and_exit;
}
+#if BFD_SUPPORTS_PLUGINS
+ /* Copy LTO IR file as unknown object. */
+ if (bfd_plugin_target_p (ibfd->xvec))
+ ok_object = false;
+ else
+#endif
if (ok_object)
{
ok = copy_object (this_element, output_element, input_arch);
@@ -3845,6 +3875,7 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
char **obj_matching;
char **core_matching;
off_t size = get_file_size (input_filename);
+ const char *target = input_target;
if (size < 1)
{
@@ -3855,9 +3886,16 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
return;
}
+#if BFD_SUPPORTS_PLUGINS
+ /* Enable LTO plugin in strip unless all LTO sections should be
+ removed. */
+ if (is_strip && !target && !lto_sections_removed)
+ target = "plugin";
+#endif
+
/* To allow us to do "strip *" without dying on the first
non-object file, failures are nonfatal. */
- ibfd = bfd_openr (input_filename, input_target);
+ ibfd = bfd_openr (input_filename, target);
if (ibfd == NULL || bfd_stat (ibfd, in_stat) != 0)
{
bfd_nonfatal_message (input_filename, NULL, NULL, NULL);
@@ -3974,17 +4012,31 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
return;
}
- if (! copy_object (ibfd, obfd, input_arch))
- status = 1;
-
- /* PR 17512: file: 0f15796a.
- If the file could not be copied it may not be in a writeable
- state. So use bfd_close_all_done to avoid the possibility of
- writing uninitialised data into the file. */
- if (! (status ? bfd_close_all_done (obfd) : bfd_close (obfd)))
+#if BFD_SUPPORTS_PLUGINS
+ if (bfd_plugin_target_p (ibfd->xvec))
{
- status = 1;
- bfd_nonfatal_message (output_filename, NULL, NULL, NULL);
+ /* Copy LTO IR file as unknown file. */
+ if (!copy_unknown_file (ibfd, obfd, in_stat->st_size,
+ in_stat->st_mode))
+ status = 1;
+ else if (!bfd_close_all_done (obfd))
+ status = 1;
+ }
+ else
+#endif
+ {
+ if (! copy_object (ibfd, obfd, input_arch))
+ status = 1;
+
+ /* PR 17512: file: 0f15796a.
+ If the file could not be copied it may not be in a writeable
+ state. So use bfd_close_all_done to avoid the possibility of
+ writing uninitialised data into the file. */
+ if (! (status ? bfd_close_all_done (obfd) : bfd_close (obfd)))
+ {
+ status = 1;
+ bfd_nonfatal_message (output_filename, NULL, NULL, NULL);
+ }
}
if (!bfd_close (ibfd))
@@ -4837,6 +4889,10 @@ strip_main (int argc, char *argv[])
char *output_file = NULL;
bool merge_notes_set = false;
+#if BFD_SUPPORTS_PLUGINS
+ bfd_plugin_set_program_name (argv[0]);
+#endif
+
while ((c = getopt_long (argc, argv, "I:O:F:K:MN:R:o:sSpdgxXHhVvwDU",
strip_options, (int *) 0)) != EOF)
{
@@ -4927,6 +4983,13 @@ strip_main (int argc, char *argv[])
case OPTION_KEEP_SECTION_SYMBOLS:
keep_section_symbols = true;
break;
+ case OPTION_PLUGIN: /* --plugin */
+#if BFD_SUPPORTS_PLUGINS
+ bfd_plugin_set_plugin (optarg);
+#else
+ fatal (_("sorry - this program has been built without plugin support\n"));
+#endif
+ break;
case 0:
/* We've been given a long option. */
break;
@@ -4971,6 +5034,14 @@ strip_main (int argc, char *argv[])
if (output_target == NULL)
output_target = input_target;
+#if BFD_SUPPORTS_PLUGINS
+ /* Check if all GCC LTO sections should be removed, assuming all LTO
+ sections will be removed with -R .gnu.lto_.*. * Remove .gnu.lto_.*
+ sections will also remove .gnu.debuglto_. sections. */
+ lto_sections_removed = !!find_section_list (".gnu.lto_.*", false,
+ SECTION_CONTEXT_REMOVE);
+#endif
+
i = optind;
if (i == argc
|| (output_file != NULL && (i + 1) < argc))
diff --git a/binutils/resbin.c b/binutils/resbin.c
index 3bce84f..889126e 100644
--- a/binutils/resbin.c
+++ b/binutils/resbin.c
@@ -1250,7 +1250,7 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data,
vst = res_alloc (sizeof (rc_ver_stringtable));
- if (!get_version_header (wrbfd, data, length, (const char *) NULL,
+ if (!get_version_header (wrbfd, data, length, "version stringtable",
&vst->language, &stverlen, &vallen,
&type, &off))
return NULL;
@@ -1284,9 +1284,9 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data,
vs = res_alloc (sizeof (rc_ver_stringinfo));
- if (!get_version_header (wrbfd, data, length,
- (const char *) NULL, &vs->key,
- &sverlen, &vallen, &type, &off))
+ if (!get_version_header (wrbfd, data, length, "version string",
+ &vs->key, &sverlen, &vallen,
+ &type, &off))
return NULL;
data += off;
@@ -1348,7 +1348,7 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data,
data += off;
length -= off;
- if (!get_version_header (wrbfd, data, length, (const char *) NULL,
+ if (!get_version_header (wrbfd, data, length, "version varfileinfo",
&vi->u.var.key, &verlen, &vallen,
&type, &off))
return NULL;
diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp
index ff93fea..cf94570 100644
--- a/binutils/testsuite/binutils-all/objcopy.exp
+++ b/binutils/testsuite/binutils-all/objcopy.exp
@@ -180,7 +180,7 @@ proc objcopy_test_verilog {testname} {
untested "verilog width-4 and width-8 tests"
return
}
-
+
foreach width {4 8} {
set got [binutils_run $OBJCOPY "-O verilog --verilog-data-width $width $binfile $verilog-$width.hex"]
if ![string equal "" $got] then {
@@ -194,7 +194,7 @@ proc objcopy_test_verilog {testname} {
}
}
- # Test generating endian correct output.
+ # Test generating endian correct output.
set testname "objcopy (verilog output endian-ness == input endian-ness)"
set got [binutils_run $OBJCOPY "-O verilog --verilog-data-width 4 $binfile $verilog-I4.hex"]
if ![string equal "" $got] then {
@@ -202,9 +202,9 @@ proc objcopy_test_verilog {testname} {
}
send_log "regexp_diff $verilog-I4.hex $srcdir/$subdir/verilog-I4.hex\n"
if {! [regexp_diff "$verilog-I4.hex" "$srcdir/$subdir/verilog-I4.hex"]} {
- pass $testname
+ pass $testname
} else {
- fail $testname
+ fail $testname
}
}