OSDN Git Service

Change linker's default behaviour - it will now reject binary files whoes
authornickc <nickc>
Mon, 23 Dec 2002 10:44:59 +0000 (10:44 +0000)
committernickc <nickc>
Mon, 23 Dec 2002 10:44:59 +0000 (10:44 +0000)
architecture it does not recognise, unless it has explicitly told to accept
them.

13 files changed:
bfd/ChangeLog
bfd/archures.c
bfd/bfd-in2.h
bfd/targets.c
binutils/ChangeLog
binutils/nlmconv.c
ld/ChangeLog
ld/NEWS
ld/ld.h
ld/ldfile.c
ld/ldlang.c
ld/ldmain.c
ld/lexsup.c

index 2e02617..106eb2c 100644 (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>
 
        * coff-arm.c (coff_arm_relocate_section): Disable WINCE workaround
index d969a9b..b73766f 100644 (file)
@@ -547,27 +547,39 @@ FUNCTION
 SYNOPSIS
        const bfd_arch_info_type *bfd_arch_get_compatible(
                const bfd *abfd,
-               const bfd *bbfd);
+               const bfd *bbfd,
+               bfd_boolean accept_unknowns);
 
 DESCRIPTION
-       Determine whether two BFDs'
-       architectures and machine types are compatible.  Calculates
-       the lowest common denominator between the two architectures
-       and machine types implied by the BFDs and returns a pointer to
-       an <<arch_info>> structure describing the compatible machine.
+       Determine whether two BFDs' architectures and machine types
+       are compatible.  Calculates the lowest common denominator
+       between the two architectures and machine types implied by
+       the BFDs and returns a pointer to an <<arch_info>> structure
+       describing the compatible machine.
 */
 
 const bfd_arch_info_type *
-bfd_arch_get_compatible (abfd, bbfd)
+bfd_arch_get_compatible (abfd, bbfd, accept_unknowns)
      const bfd *abfd;
      const bfd *bbfd;
+     bfd_boolean accept_unknowns;
 {
-  /* If either architecture is unknown, then all we can do is assume
-     the user knows what he's doing.  */
-  if (abfd->arch_info->arch == bfd_arch_unknown)
-    return bbfd->arch_info;
-  if (bbfd->arch_info->arch == bfd_arch_unknown)
-    return abfd->arch_info;
+  const bfd * ubfd = NULL;
+
+  /* Look for an unknown architecture.  */
+  if (((ubfd = abfd) && ubfd->arch_info->arch == bfd_arch_unknown)
+      || ((ubfd = bbfd) && ubfd->arch_info->arch == bfd_arch_unknown))
+    {
+      /* 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.  */
   return abfd->arch_info->compatible (abfd->arch_info, bbfd->arch_info);
index d010632..362cc8f 100644 (file)
@@ -1752,7 +1752,8 @@ bfd_arch_list PARAMS ((void));
 const bfd_arch_info_type *
 bfd_arch_get_compatible PARAMS ((
     const bfd *abfd,
-    const bfd *bbfd));
+    const bfd *bbfd,
+    bfd_boolean accept_unknowns));
 
 void
 bfd_set_arch_info PARAMS ((bfd *abfd, const bfd_arch_info_type *arg));
index 604368c..998327d 100644 (file)
@@ -1244,7 +1244,7 @@ bfd_find_target (target_name, abfd)
   else
     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)
     {
       abfd->target_defaulted = TRUE;
index f411fcd..828ae57 100644 (file)
@@ -1,5 +1,10 @@
 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>
+
        * strings.c (isgraphic): Replace definition with STRING_ISGRAPHIC
        macro.  Handle 'S' encoding, accepting 8-bit characters.
        (main): Parse 'S' encoding.
index 7d68dcd..6709461 100644 (file)
@@ -377,7 +377,8 @@ main (argc, argv)
 
   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"));
 
   /* Move the values read from the command file into outbfd.  */
index f4ede57..cc43cea 100644 (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>
 
        * ldmain.c (main): Re-order link_info initialization.  Init all
diff --git a/ld/NEWS b/ld/NEWS
index 790b263..0ed91b1 100644 (file)
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,5 +1,9 @@
 -*- 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.
 
 * Support for Texas Instruments TMS320C4x and TMS320C3x series of
diff --git a/ld/ld.h b/ld/ld.h
index 4a2aac7..75c054e 100644 (file)
--- a/ld/ld.h
+++ b/ld/ld.h
@@ -148,6 +148,12 @@ typedef struct {
      fpor overlaps.  */
   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;
 
 extern args_type command_line;
index 34a25fa..b30fbe2 100644 (file)
@@ -225,8 +225,9 @@ ldfile_try_open_bfd (attempt, entry)
              return TRUE;
            }
 
-         if ((bfd_arch_get_compatible (check, output_bfd) == NULL)
-             /* XCOFF archives can have 32 and 64 bit objects */
+         if ((bfd_arch_get_compatible (check, output_bfd,
+                                       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 (output_bfd) == bfd_target_xcoff_flavour
                    && bfd_check_format (entry->the_bfd, bfd_archive)))
index 66b4b13..9565a63 100644 (file)
@@ -3699,7 +3699,8 @@ lang_check ()
        file = file->input_statement.next)
     {
       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
         link between differing object formats when the input
index ef84e87..03a5c5a 100644 (file)
@@ -220,6 +220,7 @@ main (argc, argv)
   command_line.rpath = NULL;
   command_line.warn_mismatch = TRUE;
   command_line.check_section_addresses = TRUE;
+  command_line.accept_unknown_input_arch = FALSE;
 
   /* We initialize DEMANGLING based on the environment variable
      COLLECT_NO_DEMANGLE.  The gcc collect2 program will demangle the
index 8ce8f18..ce4cf30 100644 (file)
@@ -133,6 +133,8 @@ int parsing_defsym = 0;
 #define OPTION_NO_DEFINE_COMMON                (OPTION_SPARE_DYNAMIC_TAGS + 1)
 #define OPTION_NOSTDLIB                        (OPTION_NO_DEFINE_COMMON + 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
    parsing and the help text.  */
@@ -267,6 +269,10 @@ static const struct ld_option ld_options[] =
       '(', NULL, N_("Start a group"), TWO_DASHES },
   { {"end-group", no_argument, NULL, ')'},
       ')', 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},
       '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH },
   { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED},
@@ -1107,6 +1113,12 @@ parse_args (argc, argv)
        case OPTION_NO_CHECK_SECTIONS:
          command_line.check_section_addresses = FALSE;
          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 '(':
          if (ingroup)
            einfo (_("%P%F: may not nest groups (--help for usage)\n"));