]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Change linker's default behaviour - it will now reject binary files whoes
authorNick Clifton <nickc@redhat.com>
Mon, 23 Dec 2002 10:45:03 +0000 (10:45 +0000)
committerNick Clifton <nickc@redhat.com>
Mon, 23 Dec 2002 10:45:03 +0000 (10:45 +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 2e02617c13cfdbb09849e22a5b85e33f4d3c7a2a..106eb2cd9a3d84b4484c3e51da7c0824d34ad2fc 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 d969a9b82b8cb9e732d915e7dcd8d507708cd468..b73766f775fb9a78148a6b532fbb75af2da6c351 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 d010632650820b2908d1993fbec18a10cfcdbcdb..362cc8f04f4133ac22957a4014d729e38f16d504 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 604368c201406552331d5170e447e5a43d65e85c..998327de1d018fe7edd405d15e909b754ec01432 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 f411fcdba6495e1df7dfbd2f50fd3363eb24ea78..828ae57fcd1f27b1d4563194748c787574ee5393 100644 (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>
 
        * strings.c (isgraphic): Replace definition with STRING_ISGRAPHIC
index 7d68dcd2056e9328ef30c8713a8541e6ec60c5fc..6709461d328ace7f89e4da73d39fe0229a9362a7 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 f4ede579c53e91c0ae9a0324588daaa6cf9d9c88..cc43cea29cfbeb228752805900e618f71690fd06 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 790b263b1e43e0f5f084e97838ed1489a9970bb7..0ed91b1e554767514f30d22207acd85c1abed993 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 4a2aac71b522ffb679c6beb7be29e07d22396de2..75c054e77547d91272d1b6cd20e1be1b9705510d 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 34a25fa7b566dbb29fc03e386eb26d073713383b..b30fbe2576e984671fe28c8d2d469929afe48a13 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 66b4b13e20c3c7a5a26a7916b982f98cb7de0d8d..9565a634f3d0d013b3f9f3040703689f86f234f2 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 ef84e877550f2a65ed2b76c721105ca636729f7d..03a5c5acdcca0d57e16571092f20c8119fa8d410 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 8ce8f1805c7428b2fa29365078a0f6616b18ba44..ce4cf30994d0b67dcb27c3689fa5c9373631084e 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"));