diff options
author | Siddhesh Poyarekar <siddhesh@gotplt.org> | 2020-12-07 20:48:28 +0530 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@gotplt.org> | 2020-12-07 20:48:28 +0530 |
commit | 1a1c3b4cc17687091cff5a368bd6f13742bcfdf8 (patch) | |
tree | bba73125094ca7214e3c8613d89b943310891894 /binutils | |
parent | 365f5fb6d0f0da83817431a275e99e6f6babbe04 (diff) | |
download | fsf-binutils-gdb-1a1c3b4cc17687091cff5a368bd6f13742bcfdf8.zip fsf-binutils-gdb-1a1c3b4cc17687091cff5a368bd6f13742bcfdf8.tar.gz fsf-binutils-gdb-1a1c3b4cc17687091cff5a368bd6f13742bcfdf8.tar.bz2 |
objcopy: Get input file stat after BFD open
Get file state from the descriptor opened by copy_file for the input
BFD. This ensures continuity in the view of the input file through
the descriptor. At the moment it is only to preserve timestamps
recorded at the point that we opened the file for input but in the
next patch this state will also be used to preserve ownership and
permissions wherever applicable.
binutils/
* objcopy.c (copy_file): New argument IN_STAT. Return stat of
ibfd through it.
(strip_main): Remove redundant stat calls. adjust copy_file
calls.
(copy_main): Likewise.
Diffstat (limited to 'binutils')
-rw-r--r-- | binutils/ChangeLog | 9 | ||||
-rw-r--r-- | binutils/objcopy.c | 23 |
2 files changed, 16 insertions, 16 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog index e0794e4..a817cd8 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,6 +1,15 @@ 2020-12-07 Siddhesh Poyarekar <siddhesh@sourceware.org> PR 26945 + * objcopy.c (copy_file): New argument IN_STAT. Return stat of + ibfd through it. + (strip_main): Remove redundant stat calls. adjust copy_file + calls. + (copy_main): Likewise. + +2020-12-07 Siddhesh Poyarekar <siddhesh@sourceware.org> + + PR 26945 * bucomm.c (make_tempname): Add argument to return file descriptor. * bucomm.h (make_tempname): Likewise. diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 2eb083c..b6cf6ea 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -3729,8 +3729,8 @@ set_long_section_mode (bfd *output_bfd, bfd *input_bfd, enum long_section_name_h static void copy_file (const char *input_filename, const char *output_filename, int ofd, - const char *input_target, const char *output_target, - const bfd_arch_info_type *input_arch) + struct stat *in_stat, const char *input_target, + const char *output_target, const bfd_arch_info_type *input_arch) { bfd *ibfd; char **obj_matching; @@ -3749,7 +3749,7 @@ copy_file (const char *input_filename, const char *output_filename, int ofd, /* To allow us to do "strip *" without dying on the first non-object file, failures are nonfatal. */ ibfd = bfd_openr (input_filename, input_target); - if (ibfd == NULL) + if (ibfd == NULL || fstat (fileno (ibfd->iostream), in_stat) != 0) { bfd_nonfatal_message (input_filename, NULL, NULL, NULL); status = 1; @@ -4822,11 +4822,6 @@ strip_main (int argc, char *argv[]) continue; } - if (preserve_dates) - /* No need to check the return value of stat(). - It has already been checked in get_file_size(). */ - stat (argv[i], &statbuf); - if (output_file == NULL || filename_cmp (argv[i], output_file) == 0) tmpname = make_tempname (argv[i], &tmpfd); @@ -4842,7 +4837,8 @@ strip_main (int argc, char *argv[]) } status = 0; - copy_file (argv[i], tmpname, tmpfd, input_target, output_target, NULL); + copy_file (argv[i], tmpname, tmpfd, &statbuf, input_target, + output_target, NULL); if (status == 0) { if (preserve_dates) @@ -5899,11 +5895,6 @@ copy_main (int argc, char *argv[]) convert_efi_target (efi); } - if (preserve_dates) - if (stat (input_filename, & statbuf) < 0) - fatal (_("warning: could not locate '%s'. System error message: %s"), - input_filename, strerror (errno)); - /* If there is no destination file, or the source and destination files are the same, then create a temp and rename the result into the input. */ if (output_filename == NULL @@ -5916,8 +5907,8 @@ copy_main (int argc, char *argv[]) fatal (_("warning: could not create temporary file whilst copying '%s', (error: %s)"), input_filename, strerror (errno)); - copy_file (input_filename, tmpname, tmpfd, input_target, output_target, - input_arch); + copy_file (input_filename, tmpname, tmpfd, &statbuf, input_target, + output_target, input_arch); if (status == 0) { if (preserve_dates) |