PR24968, make objcopy use output ELF arch if -B not given
authorAlan Modra <amodra@gmail.com>
Tue, 19 Nov 2019 08:45:20 +0000 (19:15 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 19 Nov 2019 08:56:40 +0000 (19:26 +1030)
This should make objcopy -B redundant for the common case of producing
ELF output where the -O target defaults to the desired arch:mach.

PR 24968
* objcopy.c (copy_object): For ELF output and non-ELF input without
arch, take arch from output file if not given by -B.  Don't
bfd_get_arch_info when we already have iarch.

binutils/ChangeLog
binutils/objcopy.c

index 4fabf0cb063ed5ee5bf54d6ada8410ce6506ebd5..19f1c4051a0e8812d3e81a78bd3c2a569f173e2b 100644 (file)
@@ -1,3 +1,10 @@
+2019-11-19  Alan Modra  <amodra@gmail.com>
+
+       PR 24968
+       * objcopy.c (copy_object): For ELF output and non-ELF input without
+       arch, take arch from output file if not given by -B.  Don't
+       bfd_get_arch_info when we already have iarch.
+
 2019-11-19  Alan Modra  <amodra@gmail.com>
 
        PR 25191
index 551378da399c8a793a951bb21b9af1b31bd65f99..99cc7beca8f7241bddee8c0242670b4b895b0461 100644 (file)
@@ -2646,8 +2646,7 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
   imach = bfd_get_mach (ibfd);
   if (input_arch)
     {
-      if (bfd_get_arch_info (ibfd) == NULL
-         || bfd_get_arch_info (ibfd)->arch == bfd_arch_unknown)
+      if (iarch == bfd_arch_unknown)
        {
          iarch = input_arch->arch;
          imach = input_arch->mach;
@@ -2656,6 +2655,14 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
        non_fatal (_("Input file `%s' ignores binary architecture parameter."),
                   bfd_get_archive_filename (ibfd));
     }
+  if (iarch == bfd_arch_unknown
+      && bfd_get_flavour (ibfd) != bfd_target_elf_flavour
+      && bfd_get_flavour (obfd) == bfd_target_elf_flavour)
+    {
+      const struct elf_backend_data *bed = get_elf_backend_data (obfd);
+      iarch = bed->arch;
+      imach = 0;
+    }
   if (!bfd_set_arch_mach (obfd, iarch, imach)
       && (ibfd->target_defaulted
          || bfd_get_arch (ibfd) != bfd_get_arch (obfd)))
This page took 0.026679 seconds and 4 git commands to generate.