X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=binutils%2Fobjcopy.c;h=ca35df03b66f360ea750d0e23e13034b599e98bc;hb=b6fb30eda72b7fc3a6214ed2787f80971f66810d;hp=e6711a99fb2f0324c8f7edea21580daa061cfdaa;hpb=9cc89dc0acc140cb27e21d2597af42d36444673b;p=deliverable%2Fbinutils-gdb.git diff --git a/binutils/objcopy.c b/binutils/objcopy.c index e6711a99fb..ca35df03b6 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -1268,8 +1268,15 @@ group_signature (asection *group) static bfd_boolean is_dwo_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec) { - const char *name = bfd_section_name (sec); - int len = strlen (name); + const char *name; + int len; + + if (sec == NULL || (name = bfd_section_name (sec)) == NULL) + return FALSE; + + len = strlen (name); + if (len < 5) + return FALSE; return strncmp (name + len - 4, ".dwo", 4) == 0; } @@ -1443,7 +1450,7 @@ is_hidden_symbol (asymbol *sym) { elf_symbol_type *elf_sym; - elf_sym = elf_symbol_from (sym->the_bfd, sym); + elf_sym = elf_symbol_from (sym); if (elf_sym != NULL) switch (ELF_ST_VISIBILITY (elf_sym->internal_elf_sym.st_other)) { @@ -2604,7 +2611,15 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch) { /* PR 17636: Call non-fatal so that we return to our parent who may need to tidy temporary files. */ - non_fatal (_("Unable to change endianness of input file(s)")); + non_fatal (_("unable to change endianness of '%s'"), + bfd_get_archive_filename (ibfd)); + return FALSE; + } + + if (ibfd->read_only) + { + non_fatal (_("unable to modify '%s' due to errors"), + bfd_get_archive_filename (ibfd)); return FALSE; } @@ -2774,6 +2789,11 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch) file_alignment, section_alignment); } + + if (preserve_dates + && bfd_get_flavour (ibfd) == bfd_target_coff_flavour + && bfd_pei_p (ibfd)) + pe->timestamp = pe_data (ibfd)->coff.timestamp; } if (isympp) @@ -2978,6 +2998,9 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch) for (pdump = dump_sections; pdump != NULL; pdump = pdump->next) { + FILE * f; + bfd_byte *contents; + osec = bfd_get_section_by_name (ibfd, pdump->name); if (osec == NULL) { @@ -2995,14 +3018,9 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch) } bfd_size_type size = bfd_section_size (osec); - if (size == 0) - { - bfd_nonfatal_message (NULL, ibfd, osec, - _("can't dump section - it is empty")); - continue; - } + /* Note - we allow the dumping of zero-sized sections, + creating an empty file. */ - FILE * f; f = fopen (pdump->filename, FOPEN_WB); if (f == NULL) { @@ -3011,10 +3029,9 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch) continue; } - bfd_byte *contents; if (bfd_malloc_and_get_section (ibfd, osec, &contents)) { - if (fwrite (contents, 1, size, f) != size) + if (size != 0 && fwrite (contents, 1, size, f) != size) { non_fatal (_("error writing section contents to %s (error: %s)"), pdump->filename, @@ -3312,14 +3329,12 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch) /* It is likely that output sections are in the same order as the input sections, but do not assume that this is the case. */ - if (strcmp (bfd_section_name (merged->sec), - bfd_section_name (osec)) != 0) + if (merged->sec->output_section != osec) { for (merged = merged_note_sections; merged != NULL; merged = merged->next) - if (strcmp (bfd_section_name (merged->sec), - bfd_section_name (osec)) == 0) + if (merged->sec->output_section == osec) break; if (merged == NULL) @@ -4293,6 +4308,7 @@ copy_relocations_in_section (bfd *ibfd, sec_ptr isection, void *obfdarg) status = 1; bfd_nonfatal_message (NULL, ibfd, isection, _("relocation count is negative")); + free (relpp); return; } } @@ -4317,7 +4333,7 @@ copy_relocations_in_section (bfd *ibfd, sec_ptr isection, void *obfdarg) temp_relpp [temp_relcount++] = relpp [i]; } relcount = temp_relcount; - if (isection->orelocation == NULL) + if (relpp != isection->orelocation) free (relpp); relpp = temp_relpp; } @@ -4326,7 +4342,8 @@ copy_relocations_in_section (bfd *ibfd, sec_ptr isection, void *obfdarg) if (relcount == 0) { osection->flags &= ~SEC_RELOC; - free (relpp); + if (relpp != isection->orelocation) + free (relpp); } } }