This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: PR binutils/10802: objcopy an executable file compiled with PIE failed
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: binutils at sources dot redhat dot com
- Date: Mon, 19 Oct 2009 11:18:40 -0700
- Subject: PATCH: PR binutils/10802: objcopy an executable file compiled with PIE failed
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
Hi,
We failed to preserve the permission bits on PIE since it is marked as
ET_DYN. This patch tries to preserve the permission bits when copying
a file. OK to install?
Thanks.
H.J.
----
2009-10-19 H.J. Lu <hongjiu.lu@intel.com>
PR binutils/10802
* objcopy.c (copy_file): Try to preserve the permission bits.
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 9732b86..dec0feb 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -2287,6 +2287,18 @@ copy_file (const char *input_filename, const char *output_filename,
status = 1;
}
+
+ if (status == 0)
+ {
+ struct stat statbuf;
+
+ /* No need to check the return value of stat(). It has already
+ been checked in get_file_size(). */
+ stat (input_filename, &statbuf);
+
+ /* Try to preserve the permission bits. */
+ chmod (output_filename, statbuf.st_mode);
+ }
}
/* Add a name to the section renaming list. */