aboutsummaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
Diffstat (limited to 'binutils')
-rw-r--r--binutils/NEWS7
-rw-r--r--binutils/ar.c86
-rw-r--r--binutils/arsup.c14
-rw-r--r--binutils/dwarf.c17
-rw-r--r--binutils/nm.c29
-rw-r--r--binutils/objcopy.c212
-rw-r--r--binutils/resbin.c26
-rw-r--r--binutils/rescoff.c8
-rw-r--r--binutils/testsuite/binutils-all/aarch64/pei-aarch64-little.d2
-rw-r--r--binutils/testsuite/binutils-all/copy-7.d14
-rw-r--r--binutils/testsuite/binutils-all/copy-7.s7
-rw-r--r--binutils/testsuite/binutils-all/loongarch64/pei-loongarch64.d2
-rw-r--r--binutils/testsuite/binutils-all/objcopy.exp1
-rw-r--r--binutils/testsuite/binutils-all/readelf.exp5
-rw-r--r--binutils/testsuite/binutils-all/riscv/pei-riscv64.d2
-rw-r--r--binutils/testsuite/binutils-all/testranges-ia64.d2
16 files changed, 194 insertions, 240 deletions
diff --git a/binutils/NEWS b/binutils/NEWS
index 5038851..ccda855 100644
--- a/binutils/NEWS
+++ b/binutils/NEWS
@@ -1,5 +1,12 @@
-*- text -*-
+* Internal changes to plugin support, and stricter target checking may result
+ in some errors being exposed in user options passed to the various binutils.
+ For example objcopy --target=TARGET now will only work if the input file is
+ for TARGET whereas prior versions of objcopy accepted other target input
+ files and produced a TARGET output. If you do in fact want the old
+ behaviour the correct usage is objcopy --output-target=TARGET.
+
* NaCl target support is removed.
Changes in 2.45:
diff --git a/binutils/ar.c b/binutils/ar.c
index 3cac3f3..afe8633 100644
--- a/binutils/ar.c
+++ b/binutils/ar.c
@@ -32,9 +32,7 @@
#include "arsup.h"
#include "filenames.h"
#include "binemul.h"
-#if BFD_SUPPORTS_PLUGINS
#include "plugin.h"
-#endif
#ifdef __GO32___
#define EXT_NAME_LEN 3 /* Bufflen of addition to name if it's MS-DOS. */
@@ -42,12 +40,9 @@
#define EXT_NAME_LEN 6 /* Ditto for *NIX. */
#endif
-/* Static declarations. */
+/* Forward declarations. */
-static void mri_emul (void);
static const char *normalize (const char *, bfd *);
-static void remove_output (void);
-static void map_over_members (bfd *, void (*)(bfd *), char **, int);
static void print_contents (bfd * member);
static void delete_members (bfd *, char **files_to_delete);
@@ -58,8 +53,7 @@ static void print_descr (bfd * abfd);
static void write_archive (bfd *);
static int ranlib_only (const char *archname);
static int ranlib_touch (const char *archname);
-static void usage (int);
-
+
/** Globals and flags. */
static int mri_mode;
@@ -148,12 +142,6 @@ static int show_version = 0;
static int show_help = 0;
-#if BFD_SUPPORTS_PLUGINS
-static const char *plugin_target = "plugin";
-#else
-static const char *plugin_target = NULL;
-#endif
-
static const char *target = NULL;
enum long_option_numbers
@@ -280,18 +268,18 @@ usage (int help)
{
FILE *s;
-#if BFD_SUPPORTS_PLUGINS
- /* xgettext:c-format */
- const char *command_line
- = _("Usage: %s [emulation options] [-]{dmpqrstx}[abcDfilMNoOPsSTuvV]"
- " [--plugin <name>] [member-name] [count] archive-file file...\n");
+ const char *command_line;
+ if (bfd_plugin_enabled ())
+ /* xgettext:c-format */
+ command_line
+ = _("Usage: %s [emulation options] [-]{dmpqrstx}[abcDfilMNoOPsSTuvV]"
+ " [--plugin <name>] [member-name] [count] archive-file file...\n");
+ else
+ /* xgettext:c-format */
+ command_line
+ = _("Usage: %s [emulation options] [-]{dmpqrstx}[abcDfilMNoOPsSTuvV]"
+ " [member-name] [count] archive-file file...\n");
-#else
- /* xgettext:c-format */
- const char *command_line
- = _("Usage: %s [emulation options] [-]{dmpqrstx}[abcDfilMNoOPsSTuvV]"
- " [member-name] [count] archive-file file...\n");
-#endif
s = help ? stdout : stderr;
fprintf (s, command_line, program_name);
@@ -343,10 +331,11 @@ usage (int help)
fprintf (s, _(" --output=DIRNAME - specify the output directory for extraction operations\n"));
fprintf (s, _(" --record-libdeps=<text> - specify the dependencies of this library\n"));
fprintf (s, _(" --thin - make a thin archive\n"));
-#if BFD_SUPPORTS_PLUGINS
- fprintf (s, _(" optional:\n"));
- fprintf (s, _(" --plugin <p> - load the specified plugin\n"));
-#endif
+ if (bfd_plugin_enabled ())
+ {
+ fprintf (s, _(" optional:\n"));
+ fprintf (s, _(" --plugin <p> - load the specified plugin\n"));
+ }
ar_emul_usage (s);
@@ -370,10 +359,9 @@ ranlib_usage (int help)
fprintf (s, _(" Generate an index to speed access to archives\n"));
fprintf (s, _(" The options are:\n\
@<file> Read options from <file>\n"));
-#if BFD_SUPPORTS_PLUGINS
- fprintf (s, _("\
+ if (bfd_plugin_enabled ())
+ fprintf (s, _("\
--plugin <name> Load the specified plugin\n"));
-#endif
if (DEFAULT_AR_DETERMINISTIC)
fprintf (s, _("\
-D Use zero for symbol map timestamp (default)\n\
@@ -600,12 +588,9 @@ decode_options (int argc, char **argv)
deterministic = false;
break;
case OPTION_PLUGIN:
-#if BFD_SUPPORTS_PLUGINS
+ if (!bfd_plugin_enabled ())
+ fatal (_("sorry - this program has been built without plugin support\n"));
bfd_plugin_set_plugin (optarg);
-#else
- fprintf (stderr, _("sorry - this program has been built without plugin support\n"));
- xexit (1);
-#endif
break;
case OPTION_TARGET:
target = optarg;
@@ -675,12 +660,9 @@ ranlib_main (int argc, char **argv)
/* PR binutils/13493: Support plugins. */
case OPTION_PLUGIN:
-#if BFD_SUPPORTS_PLUGINS
+ if (!bfd_plugin_enabled ())
+ fatal (_("sorry - this program has been built without plugin support\n"));
bfd_plugin_set_plugin (optarg);
-#else
- fprintf (stderr, _("sorry - this program has been built without plugin support\n"));
- xexit (1);
-#endif
break;
}
}
@@ -731,9 +713,7 @@ main (int argc, char **argv)
program_name = argv[0];
xmalloc_set_program_name (program_name);
bfd_set_error_program_name (program_name);
-#if BFD_SUPPORTS_PLUGINS
bfd_plugin_set_program_name (program_name);
-#endif
expandargv (&argc, &argv);
@@ -888,7 +868,7 @@ main (int argc, char **argv)
if (! bfd_make_readable (libdeps_bfd))
fatal (_("Cannot make libdeps object readable."));
- if (bfd_find_target (plugin_target, libdeps_bfd) == NULL)
+ if (bfd_find_target (target, libdeps_bfd) == NULL)
fatal (_("Cannot reset libdeps record type."));
/* Insert our libdeps record in 2nd slot of the list of files
@@ -977,12 +957,10 @@ open_inarch (const char *archive_filename, const char *file)
struct stat sbuf;
bfd *arch;
char **matching;
+ const char *arch_target = target;
bfd_set_error (bfd_error_no_error);
- if (target == NULL)
- target = plugin_target;
-
if (stat (archive_filename, &sbuf) != 0)
{
#if !defined(__GO32__) || defined(__DJGPP__)
@@ -1008,16 +986,16 @@ open_inarch (const char *archive_filename, const char *file)
/* If the target isn't set, try to figure out the target to use
for the archive from the first object on the list. */
- if (target == NULL && file != NULL)
+ if (arch_target == NULL && file != NULL)
{
bfd *obj;
- obj = bfd_openr (file, target);
+ obj = bfd_openr (file, arch_target);
if (obj != NULL)
{
if (bfd_check_format (obj, bfd_object)
&& bfd_target_supports_archives (obj))
- target = bfd_get_target (obj);
+ arch_target = bfd_get_target (obj);
(void) bfd_close (obj);
}
}
@@ -1026,7 +1004,7 @@ open_inarch (const char *archive_filename, const char *file)
output_filename = xstrdup (archive_filename);
/* Create an empty archive. */
- arch = bfd_openw (archive_filename, target);
+ arch = bfd_openw (archive_filename, arch_target);
if (arch == NULL
|| ! bfd_set_format (arch, bfd_archive)
|| ! bfd_close (arch))
@@ -1035,7 +1013,7 @@ open_inarch (const char *archive_filename, const char *file)
non_fatal (_("creating %s"), archive_filename);
}
- arch = bfd_openr (archive_filename, target);
+ arch = bfd_openr (archive_filename, arch_target);
if (arch == NULL)
{
bloser:
@@ -1069,8 +1047,8 @@ open_inarch (const char *archive_filename, const char *file)
}
}
+ /* Open all the archive contents. */
last_one = &(arch->archive_next);
- /* Read all the contents right away, regardless. */
for (next_one = bfd_openr_next_archived_file (arch, NULL);
next_one;
next_one = bfd_openr_next_archived_file (arch, next_one))
diff --git a/binutils/arsup.c b/binutils/arsup.c
index 67cbd5c..c7b6564 100644
--- a/binutils/arsup.c
+++ b/binutils/arsup.c
@@ -32,11 +32,6 @@
#include "bucomm.h"
#include "arsup.h"
-static void map_over_list
- (bfd *, void (*function) (bfd *, bfd *), struct list *);
-static void ar_directory_doer (bfd *, bfd *);
-static void ar_addlib_doer (bfd *, bfd *);
-
extern int verbose;
extern int deterministic;
@@ -180,11 +175,7 @@ ar_open (char *name, int t)
bfd *element;
bfd *ibfd;
-#if BFD_SUPPORTS_PLUGINS
- ibfd = bfd_openr (name, "plugin");
-#else
ibfd = bfd_openr (name, NULL);
-#endif
if (!ibfd)
{
@@ -266,11 +257,7 @@ ar_addmod (struct list *list)
{
bfd *abfd;
-#if BFD_SUPPORTS_PLUGINS
- abfd = bfd_openr (list->name, "plugin");
-#else
abfd = bfd_openr (list->name, NULL);
-#endif
if (!abfd)
{
fprintf (stderr, _("%s: can't open file %s\n"),
@@ -504,7 +491,6 @@ ar_extract (struct list *list)
if (!found)
{
- bfd_openr (list->name, NULL);
fprintf (stderr, _("%s: can't find module file %s\n"),
program_name, list->name);
}
diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index f4bcb67..bc5aa2b 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -8574,6 +8574,7 @@ typedef struct Frame_Chunk
uint64_t pc_range;
unsigned int cfa_reg;
uint64_t cfa_offset;
+ bool cfa_ofs_signed_p;
unsigned int ra;
unsigned char fde_encoding;
unsigned char cfa_exp;
@@ -9071,7 +9072,8 @@ frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_reg
if (fc->cfa_exp)
strcpy (tmp, "exp");
else
- sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset);
+ sprintf (tmp, (fc->cfa_ofs_signed_p ? "%s%+" PRId64 : "%s+%" PRIu64),
+ regname (fc->cfa_reg, 1), fc->cfa_offset);
printf ("%-8s ", tmp);
for (r = 0; r < fc->ncols; r++)
@@ -9794,6 +9796,7 @@ display_debug_frames (struct dwarf_section *section,
fc->data_factor = cie->data_factor;
fc->cfa_reg = cie->cfa_reg;
fc->cfa_offset = cie->cfa_offset;
+ fc->cfa_ofs_signed_p = cie->cfa_ofs_signed_p;
fc->ra = cie->ra;
if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
{
@@ -10263,6 +10266,7 @@ display_debug_frames (struct dwarf_section *section,
printf (" DW_CFA_remember_state\n");
rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
rs->cfa_offset = fc->cfa_offset;
+ rs->cfa_ofs_signed_p = fc->cfa_ofs_signed_p;
rs->cfa_reg = fc->cfa_reg;
rs->ra = fc->ra;
rs->cfa_exp = fc->cfa_exp;
@@ -10285,6 +10289,7 @@ display_debug_frames (struct dwarf_section *section,
{
remembered_state = rs->next;
fc->cfa_offset = rs->cfa_offset;
+ fc->cfa_ofs_signed_p = rs->cfa_ofs_signed_p;
fc->cfa_reg = rs->cfa_reg;
fc->ra = rs->ra;
fc->cfa_exp = rs->cfa_exp;
@@ -10311,10 +10316,11 @@ display_debug_frames (struct dwarf_section *section,
case DW_CFA_def_cfa:
READ_ULEB (fc->cfa_reg, start, block_end);
READ_ULEB (fc->cfa_offset, start, block_end);
+ fc->cfa_ofs_signed_p = false;
fc->cfa_exp = 0;
if (! do_debug_frames_interp)
- printf (" DW_CFA_def_cfa: %s ofs %d\n",
- regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
+ printf (" DW_CFA_def_cfa: %s ofs %" PRIu64 "\n",
+ regname (fc->cfa_reg, 0), fc->cfa_offset);
break;
case DW_CFA_def_cfa_register:
@@ -10327,8 +10333,9 @@ display_debug_frames (struct dwarf_section *section,
case DW_CFA_def_cfa_offset:
READ_ULEB (fc->cfa_offset, start, block_end);
+ fc->cfa_ofs_signed_p = false;
if (! do_debug_frames_interp)
- printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset);
+ printf (" DW_CFA_def_cfa_offset: %" PRIu64 "\n", fc->cfa_offset);
break;
case DW_CFA_nop:
@@ -10448,6 +10455,7 @@ display_debug_frames (struct dwarf_section *section,
ofs = sofs;
ofs *= fc->data_factor;
fc->cfa_offset = ofs;
+ fc->cfa_ofs_signed_p = true;
fc->cfa_exp = 0;
if (! do_debug_frames_interp)
printf (" DW_CFA_def_cfa_sf: %s ofs %" PRId64 "\n",
@@ -10459,6 +10467,7 @@ display_debug_frames (struct dwarf_section *section,
ofs = sofs;
ofs *= fc->data_factor;
fc->cfa_offset = ofs;
+ fc->cfa_ofs_signed_p = true;
if (! do_debug_frames_interp)
printf (" DW_CFA_def_cfa_offset_sf: %" PRId64 "\n", ofs);
break;
diff --git a/binutils/nm.c b/binutils/nm.c
index a7f0e9d..dce9207 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -37,9 +37,7 @@
#include "bucomm.h"
#include "demanguse.h"
#include "safe-ctype.h"
-#if BFD_SUPPORTS_PLUGINS
#include "plugin.h"
-#endif
#ifndef streq
#define streq(a,b) (strcmp ((a),(b)) == 0)
@@ -222,11 +220,6 @@ static char other_format[] = "%02x";
static char desc_format[] = "%04x";
static char *target = NULL;
-#if BFD_SUPPORTS_PLUGINS
-static const char *plugin_target = "plugin";
-#else
-static const char *plugin_target = NULL;
-#endif
typedef enum unicode_display_type
{
@@ -344,10 +337,9 @@ usage (FILE *stream, int status)
-P, --portability Same as --format=posix\n"));
fprintf (stream, _("\
-r, --reverse-sort Reverse the sense of the sort\n"));
-#if BFD_SUPPORTS_PLUGINS
- fprintf (stream, _("\
+ if (bfd_plugin_enabled ())
+ fprintf (stream, _("\
--plugin NAME Load the specified plugin\n"));
-#endif
fprintf (stream, _("\
-S, --print-size Print size of defined symbols\n"));
fprintf (stream, _("\
@@ -803,9 +795,7 @@ filter_symbols (bfd *abfd, bool is_dynamic, void *minisyms,
continue;
if (bfd_lto_slim_symbol_p (abfd, sym->name)
-#if BFD_SUPPORTS_PLUGINS
&& !bfd_plugin_target_p (abfd->xvec)
-#endif
&& report_plugin_err)
{
report_plugin_err = false;
@@ -1489,10 +1479,7 @@ display_rel_file (bfd *abfd, bfd *archive_bfd)
/* lto_type is set to lto_non_ir_object when a bfd is loaded with a
compiler LTO plugin. */
if (bfd_get_lto_type (abfd) == lto_slim_ir_object
-#if BFD_SUPPORTS_PLUGINS
- && !bfd_plugin_target_p (abfd->xvec)
-#endif
- )
+ && !bfd_plugin_target_p (abfd->xvec))
{
report_plugin_err = false;
non_fatal (_("%s: plugin needed to handle lto object"),
@@ -1650,7 +1637,7 @@ display_file (char *filename)
if (get_file_size (filename) < 1)
return false;
- file = bfd_openr (filename, target ? target : plugin_target);
+ file = bfd_openr (filename, target);
if (file == NULL)
{
bfd_nonfatal (filename);
@@ -1993,9 +1980,7 @@ main (int argc, char **argv)
program_name = *argv;
xmalloc_set_program_name (program_name);
bfd_set_error_program_name (program_name);
-#if BFD_SUPPORTS_PLUGINS
bfd_plugin_set_program_name (program_name);
-#endif
expandargv (&argc, &argv);
@@ -2142,11 +2127,9 @@ main (int argc, char **argv)
break;
case OPTION_PLUGIN: /* --plugin */
-#if BFD_SUPPORTS_PLUGINS
+ if (!bfd_plugin_enabled ())
+ fatal (_("sorry - this program has been built without plugin support\n"));
bfd_plugin_set_plugin (optarg);
-#else
- fatal (_("sorry - this program has been built without plugin support\n"));
-#endif
break;
case OPTION_IFUNC_CHARS:
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 654d2b9..51d87d6 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -30,9 +30,7 @@
#include "coff/internal.h"
#include "libcoff.h"
#include "safe-ctype.h"
-#if BFD_SUPPORTS_PLUGINS
#include "plugin.h"
-#endif
/* FIXME: See bfd/peXXigen.c for why we include an architecture specific
header in generic PE code. */
@@ -168,13 +166,6 @@ 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;
-#else
-#define lto_sections_removed false
-#endif
-
/* TRUE if only some sections are to be copied. */
static bool sections_copied;
@@ -770,10 +761,9 @@ 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, _("\
+ if (bfd_plugin_enabled ())
+ fprintf (stream, _("\
--plugin NAME Load the specified plugin\n"));
-#endif
list_supported_targets (program_name, stream);
if (REPORT_BUGS_TO[0] && exit_status == 0)
@@ -3690,8 +3680,6 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
bool ok_object;
const char *element_name;
- this_element->is_strip_input = 1;
-
element_name = bfd_get_filename (this_element);
/* PR binutils/17533: Do not allow directory traversal
outside of the current directory tree by archive members. */
@@ -3748,11 +3736,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
l->obfd = NULL;
list = l;
-#if BFD_SUPPORTS_PLUGINS
- /* Ignore plugin target if all LTO sections should be removed. */
- if (lto_sections_removed)
- this_element->plugin_format = bfd_plugin_no;
-#endif
+ this_element->plugin_format = bfd_plugin_no;
ok_object = bfd_check_format (this_element, bfd_object);
/* PR binutils/3110: Cope with archives
@@ -3770,14 +3754,9 @@ 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 ((!lto_sections_removed
- && this_element->lto_type == lto_slim_ir_object)
- || bfd_plugin_target_p (this_element->xvec))
+ /* Copy slim LTO IR file as unknown object. */
+ if (this_element->lto_type == lto_slim_ir_object)
ok_object = false;
- else
-#endif
if (ok_object)
{
ok = copy_object (this_element, output_element, input_arch,
@@ -3812,7 +3791,8 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
set_times (output_name, &buf);
/* Open the newly created output file and attach to our list. */
- output_element = bfd_openr (output_name, output_target);
+ const char *targ = force_output_target ? output_target : NULL;
+ output_element = bfd_openr (output_name, targ);
list->obfd = output_element;
@@ -3869,25 +3849,6 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
return ok;
}
-static bool
-check_format_object (bfd *ibfd, char ***obj_matching,
- bool no_plugins ATTRIBUTE_UNUSED)
-{
-#if BFD_SUPPORTS_PLUGINS
- /* Ignore plugin target first if all LTO sections should be
- removed. Try with plugin target next if ignoring plugin
- target fails to match the format. */
- if (no_plugins && ibfd->plugin_format == bfd_plugin_unknown)
- {
- ibfd->plugin_format = bfd_plugin_no;
- if (bfd_check_format_matches (ibfd, bfd_object, obj_matching))
- return true;
- ibfd->plugin_format = bfd_plugin_unknown;
- }
-#endif
- return bfd_check_format_matches (ibfd, bfd_object, obj_matching);
-}
-
/* The top-level control. */
static void
@@ -3912,12 +3873,6 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
return;
}
-#if BFD_SUPPORTS_PLUGINS
- /* Enable LTO plugin in strip. */
- if (is_strip && !target)
- 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, target);
@@ -3971,7 +3926,7 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
break;
}
- ibfd->is_strip_input = 1;
+ ibfd->plugin_format = bfd_plugin_no;
if (bfd_check_format (ibfd, bfd_archive))
{
@@ -4014,16 +3969,64 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
if (!copy_archive (ibfd, obfd, output_target, force_output_target,
input_arch, target_defaulted))
status = 1;
+ return;
}
- else if (check_format_object (ibfd, &obj_matching, lto_sections_removed))
+
+ bool ok_plugin = false;
+ bool ok_object = bfd_check_format_matches (ibfd, bfd_object, &obj_matching);
+ bfd_error_type obj_error = bfd_get_error ();
+ bfd_error_type core_error = bfd_error_no_error;
+ if (!ok_object)
+ {
+ ok_object = bfd_check_format_matches (ibfd, bfd_core, &core_matching);
+ core_error = bfd_get_error ();
+ if (ok_object)
+ {
+ if (obj_error == bfd_error_file_ambiguously_recognized)
+ free (obj_matching);
+ obj_error = bfd_error_no_error;
+ }
+ else if (bfd_plugin_enabled ())
+ {
+ /* This is for LLVM bytecode files, which are not ELF objects.
+ Since objcopy/strip does nothing with these files except
+ copy them whole perhaps we ought to just reject them? */
+ bfd_find_target ("plugin", ibfd);
+ ibfd->plugin_format = bfd_plugin_unknown;
+ ok_plugin = bfd_check_format (ibfd, bfd_object);
+ }
+ }
+
+ if (obj_error == bfd_error_file_ambiguously_recognized)
+ {
+ if (core_error == bfd_error_file_ambiguously_recognized)
+ free (core_matching);
+ bfd_set_error (obj_error);
+ status = 1;
+ bfd_nonfatal_message (input_filename, NULL, NULL, NULL);
+ list_matching_formats (obj_matching);
+ }
+ else if (core_error == bfd_error_file_ambiguously_recognized)
+ {
+ status = 1;
+ bfd_nonfatal_message (input_filename, NULL, NULL, NULL);
+ list_matching_formats (core_matching);
+ }
+ else if (!ok_object && !ok_plugin)
+ {
+ status = 1;
+ bfd_set_error (obj_error);
+ bfd_nonfatal_message (input_filename, NULL, NULL, NULL);
+ }
+ else
{
bfd *obfd;
- do_copy:
/* bfd_get_target does not return the correct value until
bfd_check_format succeeds. */
- if (output_target == NULL
- || strcmp (output_target, "default") == 0)
+ if (ok_object
+ && (output_target == NULL
+ || strcmp (output_target, "default") == 0))
output_target = bfd_get_target (ibfd);
if (ofd >= 0)
@@ -4041,66 +4044,30 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
return;
}
-#if BFD_SUPPORTS_PLUGINS
- if (bfd_plugin_target_p (ibfd->xvec))
- {
- /* 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, target_defaulted))
- 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);
- }
- }
+ /* Copy slim LTO IR file as unknown file. */
+ if (ibfd->lto_type == lto_slim_ir_object)
+ ok_object = false;
+ if (ok_object
+ ? !copy_object (ibfd, obfd, input_arch, target_defaulted)
+ : !copy_unknown_file (ibfd, obfd,
+ in_stat->st_size, in_stat->st_mode))
+ status = 1;
- if (!bfd_close (ibfd))
+ /* 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 (!(ok_object && !status ? bfd_close : bfd_close_all_done) (obfd))
{
status = 1;
- bfd_nonfatal_message (input_filename, NULL, NULL, NULL);
+ bfd_nonfatal_message (output_filename, NULL, NULL, NULL);
}
}
- else
- {
- bfd_error_type obj_error = bfd_get_error ();
- bfd_error_type core_error;
-
- if (bfd_check_format_matches (ibfd, bfd_core, &core_matching))
- {
- /* This probably can't happen.. */
- if (obj_error == bfd_error_file_ambiguously_recognized)
- free (obj_matching);
- goto do_copy;
- }
-
- core_error = bfd_get_error ();
- /* Report the object error in preference to the core error. */
- if (obj_error != core_error)
- bfd_set_error (obj_error);
-
- bfd_nonfatal_message (input_filename, NULL, NULL, NULL);
- if (obj_error == bfd_error_file_ambiguously_recognized)
- list_matching_formats (obj_matching);
- if (core_error == bfd_error_file_ambiguously_recognized)
- list_matching_formats (core_matching);
-
- bfd_close (ibfd);
+ if (!bfd_close (ibfd))
+ {
status = 1;
+ bfd_nonfatal_message (input_filename, NULL, NULL, NULL);
}
}
@@ -4924,9 +4891,7 @@ 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)
@@ -5019,11 +4984,9 @@ strip_main (int argc, char *argv[])
keep_section_symbols = true;
break;
case OPTION_PLUGIN: /* --plugin */
-#if BFD_SUPPORTS_PLUGINS
+ if (!bfd_plugin_enabled ())
+ fatal (_("sorry - this program has been built without plugin support\n"));
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. */
@@ -5069,22 +5032,15 @@ 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. LLVM IR
- bitcode is stored in .llvm.lto section which will be removed with
- -R .llvm.lto. */
- lto_sections_removed = (!!find_section_list (".gnu.lto_.*", false,
- SECTION_CONTEXT_REMOVE)
- || !!find_section_list (".llvm.lto", false,
- SECTION_CONTEXT_REMOVE));
- /* NB: Must keep .gnu.debuglto_* sections unless all GCC LTO sections
+ sections will be removed with -R .gnu.lto_.*. Remove .gnu.lto_.*
+ sections will also remove .gnu.debuglto_.* sections.
+
+ NB: Must keep .gnu.debuglto_* sections unless all GCC LTO sections
will be removed to avoid undefined references to symbols in GCC LTO
debug sections. */
- if (!lto_sections_removed)
+ if (!find_section_list (".gnu.lto_.*", false, SECTION_CONTEXT_REMOVE))
find_section_list (".gnu.debuglto_*", true, SECTION_CONTEXT_KEEP);
-#endif
i = optind;
if (i == argc
diff --git a/binutils/resbin.c b/binutils/resbin.c
index fa77cd4..02905b9 100644
--- a/binutils/resbin.c
+++ b/binutils/resbin.c
@@ -1060,8 +1060,14 @@ get_version_header (windres_bfd *wrbfd, const bfd_byte *data,
*vallen = windres_get_16 (wrbfd, data + 2);
*type = windres_get_16 (wrbfd, data + 4);
- *off = 6;
+ if (*len > length)
+ {
+ non_fatal (_("version length %lu greater than resource length %lu"),
+ (unsigned long) *len, (unsigned long) length);
+ return false;
+ }
+ *off = 6;
length -= 6;
data += 6;
@@ -1101,6 +1107,14 @@ get_version_header (windres_bfd *wrbfd, const bfd_byte *data,
}
*off = (*off + 3) &~ 3;
+
+ if (*len < *off)
+ {
+ non_fatal (_("version length %lu does not cover header length %lu"),
+ (unsigned long) *len, (unsigned long) *off);
+ return false;
+ }
+
return true;
}
@@ -1120,14 +1134,6 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data,
(unichar **) NULL, &verlen, &vallen, &type, &off))
return NULL;
- /* PR 17512: The verlen field does not include padding length. */
- if (verlen > length)
- {
- non_fatal (_("version length %lu greater than resource length %lu"),
- (unsigned long) verlen, (unsigned long) length);
- return NULL;
- }
-
if (type != 0)
{
non_fatal (_("unexpected version type %d"), (int) type);
@@ -1311,7 +1317,7 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data,
if (stverlen < sverlen)
{
non_fatal (_("unexpected version string length %ld < %ld"),
- (long) verlen, (long) sverlen);
+ (long) stverlen, (long) sverlen);
return NULL;
}
stverlen -= sverlen;
diff --git a/binutils/rescoff.c b/binutils/rescoff.c
index 14546a4..efcdba4 100644
--- a/binutils/rescoff.c
+++ b/binutils/rescoff.c
@@ -308,6 +308,8 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
re->subdir = 1;
re->u.dir = read_coff_res_dir (wrbfd, flaginfo->data + rva, flaginfo,
type, level + 1);
+ if (re->u.dir == NULL)
+ return NULL;
}
else
{
@@ -319,6 +321,8 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
re->subdir = 0;
re->u.res = read_coff_data_entry (wrbfd, flaginfo->data + rva,
flaginfo, type);
+ if (re->u.res == NULL)
+ return NULL;
}
*pp = re;
@@ -359,6 +363,8 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
re->subdir = 1;
re->u.dir = read_coff_res_dir (wrbfd, flaginfo->data + rva, flaginfo,
type, level + 1);
+ if (re->u.dir == NULL)
+ return NULL;
}
else
{
@@ -370,6 +376,8 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
re->subdir = 0;
re->u.res = read_coff_data_entry (wrbfd, flaginfo->data + rva,
flaginfo, type);
+ if (re->u.res == NULL)
+ return NULL;
}
*pp = re;
diff --git a/binutils/testsuite/binutils-all/aarch64/pei-aarch64-little.d b/binutils/testsuite/binutils-all/aarch64/pei-aarch64-little.d
index 27cb6e1..22f6649 100644
--- a/binutils/testsuite/binutils-all/aarch64/pei-aarch64-little.d
+++ b/binutils/testsuite/binutils-all/aarch64/pei-aarch64-little.d
@@ -1,7 +1,7 @@
#skip: aarch64_be-*-*
#ld: -e0
#PROG: objcopy
-#objcopy: -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* -j .reloc --target=efi-app-aarch64
+#objcopy: -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* -j .reloc --output-target=efi-app-aarch64
#objdump: -h -f
#name: Check if efi app format is recognized
diff --git a/binutils/testsuite/binutils-all/copy-7.d b/binutils/testsuite/binutils-all/copy-7.d
new file mode 100644
index 0000000..ac8e756
--- /dev/null
+++ b/binutils/testsuite/binutils-all/copy-7.d
@@ -0,0 +1,14 @@
+#PROG: objcopy
+#readelf: -tW
+#name: copy with unknown section flag
+#warning: .*/copy-7[.].*:[.]special: warning: retaining .* 0x10000
+
+There are .* section headers, starting at offset .*
+
+Section Headers:
+ \[Nr\].*
+#...
+ \[ [1-9]\] .special
+ PROGBITS .*
+ \[0+10000\]: UNKNOWN \(0+10000\)
+#...
diff --git a/binutils/testsuite/binutils-all/copy-7.s b/binutils/testsuite/binutils-all/copy-7.s
new file mode 100644
index 0000000..0861c3c
--- /dev/null
+++ b/binutils/testsuite/binutils-all/copy-7.s
@@ -0,0 +1,7 @@
+ .globl text_symbol
+ .text
+text_symbol:
+ .nop
+
+ .section .special,"0x10000", %progbits
+ .long -1
diff --git a/binutils/testsuite/binutils-all/loongarch64/pei-loongarch64.d b/binutils/testsuite/binutils-all/loongarch64/pei-loongarch64.d
index 574b3e5..61b026d 100644
--- a/binutils/testsuite/binutils-all/loongarch64/pei-loongarch64.d
+++ b/binutils/testsuite/binutils-all/loongarch64/pei-loongarch64.d
@@ -1,6 +1,6 @@
#ld: -e0
#PROG: objcopy
-#objcopy: -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* -j .reloc --target=pei-loongarch64
+#objcopy: -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* -j .reloc --output-target=pei-loongarch64
#objdump: -h -f
#name: Check if efi app format is recognized
diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp
index 89370bc..ac8978f 100644
--- a/binutils/testsuite/binutils-all/objcopy.exp
+++ b/binutils/testsuite/binutils-all/objcopy.exp
@@ -1313,6 +1313,7 @@ if [is_elf_format] {
run_dump_test "group-7b"
run_dump_test "group-7c"
run_dump_test "copy-1"
+ run_dump_test "copy-7"
run_dump_test "note-1"
# Use copytest.o from the note-1 test to determine ELF32 or ELF64
if [is_elf64 tmpdir/copytest.o] {
diff --git a/binutils/testsuite/binutils-all/readelf.exp b/binutils/testsuite/binutils-all/readelf.exp
index 571bb99..22f2a35 100644
--- a/binutils/testsuite/binutils-all/readelf.exp
+++ b/binutils/testsuite/binutils-all/readelf.exp
@@ -317,22 +317,21 @@ proc readelf_thin_archive_test {} {
if ![is_remote host] {
set tempfile tmpdir/bintest.o
- set templib tmpdir/bintest.thin.a
set libname tmpdir/bintest.thin.a
} else {
set tempfile [remote_download host tmpdir/bintest.o]
- set templib [remote_download host tmpdir/bintest.thin.a]
set libname bintest.thin.a
}
set testname "readelf -h bintest.thin"
+ file_on_host delete $libname
set got [binutils_run $AR "rcT $libname ${tempfile}"]
if ![string match "" $got] {
fail $testname
return
}
- readelf_test -h $templib readelf.h.thin
+ readelf_test -h $libname readelf.h.thin
pass $testname
}
diff --git a/binutils/testsuite/binutils-all/riscv/pei-riscv64.d b/binutils/testsuite/binutils-all/riscv/pei-riscv64.d
index 189b016..4316414 100644
--- a/binutils/testsuite/binutils-all/riscv/pei-riscv64.d
+++ b/binutils/testsuite/binutils-all/riscv/pei-riscv64.d
@@ -1,7 +1,7 @@
#as: -march=rv64gc -mabi=lp64d
#ld: -m elf64lriscv -e0
#PROG: objcopy
-#objcopy: -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* -j .reloc --target=pei-riscv64-little
+#objcopy: -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* -j .reloc --output-target=pei-riscv64-little
#objdump: -h -f
#name: Check if efi app format is recognized
diff --git a/binutils/testsuite/binutils-all/testranges-ia64.d b/binutils/testsuite/binutils-all/testranges-ia64.d
index e1e29e7..26963c9 100644
--- a/binutils/testsuite/binutils-all/testranges-ia64.d
+++ b/binutils/testsuite/binutils-all/testranges-ia64.d
@@ -1,7 +1,7 @@
#PROG: objcopy
#source: testranges-ia64.s
#readelf: -wR --wide
-#name: unordered .debug_info references to .debug_ranges
+#name: unordered .debug_info references to .debug_ranges (ia64)
#target: ia64-*-*
Contents of the .debug_ranges section: