Change linker's default behaviour - it will now reject binary files whoes

architecture it does not recognise, unless it has explicitly told to accept
them.
This commit is contained in:
Nick Clifton 2002-12-23 10:45:03 +00:00
parent 8745eafadc
commit 312b768e2f
13 changed files with 85 additions and 19 deletions

View file

@ -1,3 +1,10 @@
2002-12-23 Nick Clifton <nickc@redhat.com>
* archures.c (bfd_arch_get_compatible): Add third parameter
'accept_unknowns'. Only accept unknown format BFDs if
accept_unknowns is true, or if the format is "binary".
* bfd-in2.h: Regenerate.
2002-12-21 Nick Clifton <nickc@redhat.com> 2002-12-21 Nick Clifton <nickc@redhat.com>
* coff-arm.c (coff_arm_relocate_section): Disable WINCE workaround * coff-arm.c (coff_arm_relocate_section): Disable WINCE workaround

View file

@ -547,27 +547,39 @@ FUNCTION
SYNOPSIS SYNOPSIS
const bfd_arch_info_type *bfd_arch_get_compatible( const bfd_arch_info_type *bfd_arch_get_compatible(
const bfd *abfd, const bfd *abfd,
const bfd *bbfd); const bfd *bbfd,
bfd_boolean accept_unknowns);
DESCRIPTION DESCRIPTION
Determine whether two BFDs' Determine whether two BFDs' architectures and machine types
architectures and machine types are compatible. Calculates are compatible. Calculates the lowest common denominator
the lowest common denominator between the two architectures between the two architectures and machine types implied by
and machine types implied by the BFDs and returns a pointer to the BFDs and returns a pointer to an <<arch_info>> structure
an <<arch_info>> structure describing the compatible machine. describing the compatible machine.
*/ */
const bfd_arch_info_type * const bfd_arch_info_type *
bfd_arch_get_compatible (abfd, bbfd) bfd_arch_get_compatible (abfd, bbfd, accept_unknowns)
const bfd *abfd; const bfd *abfd;
const bfd *bbfd; const bfd *bbfd;
bfd_boolean accept_unknowns;
{ {
/* If either architecture is unknown, then all we can do is assume const bfd * ubfd = NULL;
the user knows what he's doing. */
if (abfd->arch_info->arch == bfd_arch_unknown) /* Look for an unknown architecture. */
return bbfd->arch_info; if (((ubfd = abfd) && ubfd->arch_info->arch == bfd_arch_unknown)
if (bbfd->arch_info->arch == bfd_arch_unknown) || ((ubfd = bbfd) && ubfd->arch_info->arch == bfd_arch_unknown))
return abfd->arch_info; {
/* We can allow an unknown architecture if accept_unknowns
is true, or if the target is the "binary" format, which
has an unknown architecture. Since the binary format can
only be set by explicit request from the user, it is safe
to assume that they know what they are doing. */
if (accept_unknowns
|| strcmp (bfd_get_target (ubfd), "binary") == 0)
return ubfd->arch_info;
return NULL;
}
/* Otherwise architecture-specific code has to decide. */ /* Otherwise architecture-specific code has to decide. */
return abfd->arch_info->compatible (abfd->arch_info, bbfd->arch_info); return abfd->arch_info->compatible (abfd->arch_info, bbfd->arch_info);

View file

@ -1752,7 +1752,8 @@ bfd_arch_list PARAMS ((void));
const bfd_arch_info_type * const bfd_arch_info_type *
bfd_arch_get_compatible PARAMS (( bfd_arch_get_compatible PARAMS ((
const bfd *abfd, const bfd *abfd,
const bfd *bbfd)); const bfd *bbfd,
bfd_boolean accept_unknowns));
void void
bfd_set_arch_info PARAMS ((bfd *abfd, const bfd_arch_info_type *arg)); bfd_set_arch_info PARAMS ((bfd *abfd, const bfd_arch_info_type *arg));

View file

@ -1244,7 +1244,7 @@ bfd_find_target (target_name, abfd)
else else
targname = getenv ("GNUTARGET"); targname = getenv ("GNUTARGET");
/* This is safe; the vector cannot be null */ /* This is safe; the vector cannot be null. */
if (targname == NULL || strcmp (targname, "default") == 0) if (targname == NULL || strcmp (targname, "default") == 0)
{ {
abfd->target_defaulted = TRUE; abfd->target_defaulted = TRUE;

View file

@ -1,3 +1,8 @@
2002-12-23 Nick Clifton <nickc@redhat.com>
* nlmconv.c (main): Pass TRUE as third argument to
bfd_arch_get_compatible.
2002-12-23 Nick Clifton <nickc@redhat.com> 2002-12-23 Nick Clifton <nickc@redhat.com>
* strings.c (isgraphic): Replace definition with STRING_ISGRAPHIC * strings.c (isgraphic): Replace definition with STRING_ISGRAPHIC

View file

@ -377,7 +377,8 @@ main (argc, argv)
assert (bfd_get_flavour (outbfd) == bfd_target_nlm_flavour); assert (bfd_get_flavour (outbfd) == bfd_target_nlm_flavour);
if (bfd_arch_get_compatible (inbfd, outbfd) == NULL) /* XXX: Should we accept the unknown bfd format here ? */
if (bfd_arch_get_compatible (inbfd, outbfd, TRUE) == NULL)
non_fatal (_("warning: input and output formats are not compatible")); non_fatal (_("warning: input and output formats are not compatible"));
/* Move the values read from the command file into outbfd. */ /* Move the values read from the command file into outbfd. */

View file

@ -1,3 +1,18 @@
2002-12-23 Nick Clifton <nickc@redhat.com>
* ld.h (struct args_type): Add new field
'accept_unknown_input_architecture'.
* ldmain.c (main): Initialise 'accept_unknown_input_architecture'
to false.
* ldlang.c (lang_check): Pass accept_unknown_input_architecture to
bfd_arch_get_compatible.
* ldfile.c (ldfile_try_open_bfd): Likewise.
* lexsup.c (ld_options): Add new command line switch
--accept-unknown-input-architecture and its inverse.
(parse_args): Handle --accept-unknown-input-architecture.
* ld.texinfo: Document new linker option.
* NEWS: Mention new linker option.
2002-12-20 Alan Modra <amodra@bigpond.net.au> 2002-12-20 Alan Modra <amodra@bigpond.net.au>
* ldmain.c (main): Re-order link_info initialization. Init all * ldmain.c (main): Re-order link_info initialization. Init all

View file

@ -1,5 +1,9 @@
-*- text -*- -*- text -*-
* Added --accept-unknown-linker-format to restore old linker behaviour (pre
2.14) of silently accepting and linking in any files in an unknown binary
file format.
* Added --no-omagic to undo the effects of the -N option. * Added --no-omagic to undo the effects of the -N option.
* Support for Texas Instruments TMS320C4x and TMS320C3x series of * Support for Texas Instruments TMS320C4x and TMS320C3x series of

View file

@ -148,6 +148,12 @@ typedef struct {
fpor overlaps. */ fpor overlaps. */
bfd_boolean check_section_addresses; bfd_boolean check_section_addresses;
/* If TRUE allow the linking of input files in an unknown architecture
assuming that the user knows what they are doing. This was the old
behaviour of the linker. The new default behaviour is to reject such
input files. */
bfd_boolean accept_unknown_input_arch;
} args_type; } args_type;
extern args_type command_line; extern args_type command_line;

View file

@ -225,8 +225,9 @@ ldfile_try_open_bfd (attempt, entry)
return TRUE; return TRUE;
} }
if ((bfd_arch_get_compatible (check, output_bfd) == NULL) if ((bfd_arch_get_compatible (check, output_bfd,
/* XCOFF archives can have 32 and 64 bit objects */ command_line.accept_unknown_input_arch) == NULL)
/* XCOFF archives can have 32 and 64 bit objects. */
&& ! (bfd_get_flavour (check) == bfd_target_xcoff_flavour && ! (bfd_get_flavour (check) == bfd_target_xcoff_flavour
&& bfd_get_flavour (output_bfd) == bfd_target_xcoff_flavour && bfd_get_flavour (output_bfd) == bfd_target_xcoff_flavour
&& bfd_check_format (entry->the_bfd, bfd_archive))) && bfd_check_format (entry->the_bfd, bfd_archive)))

View file

@ -3699,7 +3699,8 @@ lang_check ()
file = file->input_statement.next) file = file->input_statement.next)
{ {
input_bfd = file->input_statement.the_bfd; input_bfd = file->input_statement.the_bfd;
compatible = bfd_arch_get_compatible (input_bfd, output_bfd); compatible = bfd_arch_get_compatible (input_bfd, output_bfd,
command_line.accept_unknown_input_arch);
/* In general it is not possible to perform a relocatable /* In general it is not possible to perform a relocatable
link between differing object formats when the input link between differing object formats when the input

View file

@ -220,6 +220,7 @@ main (argc, argv)
command_line.rpath = NULL; command_line.rpath = NULL;
command_line.warn_mismatch = TRUE; command_line.warn_mismatch = TRUE;
command_line.check_section_addresses = TRUE; command_line.check_section_addresses = TRUE;
command_line.accept_unknown_input_arch = FALSE;
/* We initialize DEMANGLING based on the environment variable /* We initialize DEMANGLING based on the environment variable
COLLECT_NO_DEMANGLE. The gcc collect2 program will demangle the COLLECT_NO_DEMANGLE. The gcc collect2 program will demangle the

View file

@ -133,6 +133,8 @@ int parsing_defsym = 0;
#define OPTION_NO_DEFINE_COMMON (OPTION_SPARE_DYNAMIC_TAGS + 1) #define OPTION_NO_DEFINE_COMMON (OPTION_SPARE_DYNAMIC_TAGS + 1)
#define OPTION_NOSTDLIB (OPTION_NO_DEFINE_COMMON + 1) #define OPTION_NOSTDLIB (OPTION_NO_DEFINE_COMMON + 1)
#define OPTION_NO_OMAGIC (OPTION_NOSTDLIB + 1) #define OPTION_NO_OMAGIC (OPTION_NOSTDLIB + 1)
#define OPTION_ACCEPT_UNKNOWN_INPUT_ARCH (OPTION_NO_OMAGIC + 1)
#define OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH (OPTION_ACCEPT_UNKNOWN_INPUT_ARCH + 1)
/* The long options. This structure is used for both the option /* The long options. This structure is used for both the option
parsing and the help text. */ parsing and the help text. */
@ -267,6 +269,10 @@ static const struct ld_option ld_options[] =
'(', NULL, N_("Start a group"), TWO_DASHES }, '(', NULL, N_("Start a group"), TWO_DASHES },
{ {"end-group", no_argument, NULL, ')'}, { {"end-group", no_argument, NULL, ')'},
')', NULL, N_("End a group"), TWO_DASHES }, ')', NULL, N_("End a group"), TWO_DASHES },
{ {"accept-unknown-input-arch", no_argument, NULL, OPTION_ACCEPT_UNKNOWN_INPUT_ARCH},
'\0', NULL, N_("Accept input files whose architecture cannot be determined"), TWO_DASHES },
{ {"no-accept-unknown-input-arch", no_argument, NULL, OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH},
'\0', NULL, N_("Reject input files whose architecture is unknown"), TWO_DASHES },
{ {"assert", required_argument, NULL, OPTION_ASSERT}, { {"assert", required_argument, NULL, OPTION_ASSERT},
'\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH }, '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH },
{ {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED}, { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED},
@ -1107,6 +1113,12 @@ parse_args (argc, argv)
case OPTION_NO_CHECK_SECTIONS: case OPTION_NO_CHECK_SECTIONS:
command_line.check_section_addresses = FALSE; command_line.check_section_addresses = FALSE;
break; break;
case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH:
command_line.accept_unknown_input_arch = TRUE;
break;
case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH:
command_line.accept_unknown_input_arch = FALSE;
break;
case '(': case '(':
if (ingroup) if (ingroup)
einfo (_("%P%F: may not nest groups (--help for usage)\n")); einfo (_("%P%F: may not nest groups (--help for usage)\n"));