diff options
Diffstat (limited to 'binutils/objcopy.c')
-rw-r--r-- | binutils/objcopy.c | 72 |
1 files changed, 46 insertions, 26 deletions
diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 8c90773..5774711 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -2529,7 +2529,6 @@ merge_gnu_build_notes (bfd * abfd, /* Reconstruct the ELF notes. */ bfd_byte * new_contents; - bfd_byte * old; bfd_byte * new; bfd_vma prev_start = 0; bfd_vma prev_end = 0; @@ -2537,12 +2536,8 @@ merge_gnu_build_notes (bfd * abfd, /* Not sure how, but the notes might grow in size. (eg see PR 1774507). Allow for this here. */ new = new_contents = xmalloc (size * 2); - for (pnote = pnotes, old = contents; - pnote < pnotes_end; - pnote ++) + for (pnote = pnotes; pnote < pnotes_end; pnote ++) { - bfd_size_type note_size = 12 + pnote->padded_namesz + pnote->note.descsz; - if (! is_deleted_note (pnote)) { /* Create the note, potentially using the @@ -2585,8 +2580,6 @@ merge_gnu_build_notes (bfd * abfd, prev_end = pnote->end; } } - - old += note_size; } #if DEBUG_MERGE @@ -2668,7 +2661,8 @@ set_long_section_mode (bfd *output_bfd, bfd *input_bfd, enum long_section_name_h Returns TRUE upon success, FALSE otherwise. */ static bool -copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch) +copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch, + bool target_defaulted) { bfd_vma start; long symcount; @@ -2819,7 +2813,7 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch) imach = 0; } if (!bfd_set_arch_mach (obfd, iarch, imach) - && (ibfd->target_defaulted + && (target_defaulted || bfd_get_arch (ibfd) != bfd_get_arch (obfd))) { if (bfd_get_arch (ibfd) == bfd_arch_unknown) @@ -3622,7 +3616,8 @@ fail: static bool copy_archive (bfd *ibfd, bfd *obfd, const char *output_target, bool force_output_target, - const bfd_arch_info_type *input_arch) + const bfd_arch_info_type *input_arch, + bool target_defaulted) { struct name_list { @@ -3748,10 +3743,13 @@ 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. */ + ok_object = bfd_check_format_lto (this_element, bfd_object, + lto_sections_removed); +#else ok_object = bfd_check_format (this_element, bfd_object); - if (!ok_object) - bfd_nonfatal_message (NULL, this_element, NULL, - _("Unable to recognise the format of file")); +#endif /* PR binutils/3110: Cope with archives containing multiple target types. */ @@ -3776,7 +3774,8 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target, #endif if (ok_object) { - ok = copy_object (this_element, output_element, input_arch); + ok = copy_object (this_element, output_element, input_arch, + target_defaulted); if (!ok && bfd_get_arch (this_element) == bfd_arch_unknown) /* Try again as an unknown object file. */ @@ -3876,6 +3875,8 @@ copy_file (const char *input_filename, const char *output_filename, int ofd, char **core_matching; off_t size = get_file_size (input_filename); const char *target = input_target; + bool target_defaulted = (!input_target + || strcmp (input_target, "default") == 0); if (size < 1) { @@ -3887,9 +3888,8 @@ copy_file (const char *input_filename, const char *output_filename, int ofd, } #if BFD_SUPPORTS_PLUGINS - /* Enable LTO plugin in strip unless all LTO sections should be - removed. */ - if (is_strip && !target && !lto_sections_removed) + /* Enable LTO plugin in strip. */ + if (is_strip && !target) target = "plugin"; #endif @@ -3953,7 +3953,8 @@ copy_file (const char *input_filename, const char *output_filename, int ofd, /* bfd_get_target does not return the correct value until bfd_check_format succeeds. */ - if (output_target == NULL) + if (output_target == NULL + || strcmp (output_target, "default") == 0) { output_target = bfd_get_target (ibfd); force_output_target = false; @@ -3984,17 +3985,32 @@ copy_file (const char *input_filename, const char *output_filename, int ofd, } if (!copy_archive (ibfd, obfd, output_target, force_output_target, - input_arch)) + input_arch, target_defaulted)) status = 1; } - else if (bfd_check_format_matches (ibfd, bfd_object, &obj_matching)) + else if ( +#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. */ + bfd_check_format_matches_lto (ibfd, bfd_object, &obj_matching, + lto_sections_removed) + || (lto_sections_removed + && bfd_check_format_matches_lto (ibfd, bfd_object, + &obj_matching, false)) +#else + bfd_check_format_matches_lto (ibfd, bfd_object, &obj_matching, + false) +#endif + ) { bfd *obfd; do_copy: /* bfd_get_target does not return the correct value until bfd_check_format succeeds. */ - if (output_target == NULL) + if (output_target == NULL + || strcmp (output_target, "default") == 0) output_target = bfd_get_target (ibfd); if (ofd >= 0) @@ -4025,7 +4041,7 @@ copy_file (const char *input_filename, const char *output_filename, int ofd, else #endif { - if (! copy_object (ibfd, obfd, input_arch)) + if (! copy_object (ibfd, obfd, input_arch, target_defaulted)) status = 1; /* PR 17512: file: 0f15796a. @@ -5043,9 +5059,13 @@ strip_main (int argc, char *argv[]) #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. */ - lto_sections_removed = !!find_section_list (".gnu.lto_.*", false, - SECTION_CONTEXT_REMOVE); + 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)); #endif i = optind; |