https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88422
--- Comment #6 from Nidal Faour <nidal.faour at wdc dot com> --- Andrew Pinski is right, after chasing this bug with the help of Andrew Burgess in the file simple-object.c, calling the creat outfd = creat (dest, 00777); the creat function wraps the open function but do not pass open mode and the fix mentioned by Adrew was as follow: When opening output files for simple-object creation, we must ensure that the file is opened in binary mode. Failure to do so causes file corruption, and LTO failure on Windows targets. libiberty/ChangeLog: PR lto/88422 * simple-object.c (O_BINARY): Define if not already defined. (simple_object_copy_lto_debug_sections): Create file in binary mode. --- libiberty/ChangeLog | 7 +++++++ libiberty/simple-object.c | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libiberty/simple-object.c b/libiberty/simple-object.c index c1f38cee8ee..e061073abd1 100644 --- a/libiberty/simple-object.c +++ b/libiberty/simple-object.c @@ -44,6 +44,10 @@ Boston, MA 02110-1301, USA. */ #define SEEK_SET 0 #endif +#ifndef O_BINARY +# define O_BINARY 0 +#endif + #include "simple-object-common.h" /* The known object file formats. */ @@ -349,7 +353,7 @@ simple_object_copy_lto_debug_sections (simple_object_read *sobj, return errmsg; } - outfd = creat (dest, 00777); + outfd = open (dest, O_CREAT|O_WRONLY|O_TRUNC|O_BINARY, 00777); if (outfd == -1) { *err = errno; --