https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93196
--- Comment #16 from Andrew Pinski <pinskia at gcc dot gnu.org> --- I don't see anything wrong with strace of the -O2 case. In fact I see: [pid 10270] stat("a.out", {st_mode=S_IFREG|0755, st_size=8592, ...}) = 0 [pid 10270] lstat("a.out", {st_mode=S_IFREG|0755, st_size=8592, ...}) = 0 [pid 10270] unlink("a.out") = 0 [pid 10270] open("a.out", O_RDWR|O_CREAT|O_TRUNC, 0666) = 3 .... ;; lots of writes [pid 10270] close(3) = 0 [pid 10270] stat("a.out", {st_mode=S_IFREG|0644, st_size=8592, ...}) = 0 [pid 10270] umask(0) = 022 [pid 10270] umask(022) = 0 [pid 10270] chmod("a.out", 0755) = 0 The only thing I can think of is that the filesystem you are using has a race condition in it; in that the unlink happens after the open even though it was invoked first. I have seen this when this when using NFS servers sometimes. What file system are you using?