G++ creates unusable executable with -gdwarf-5 -Og, without any diagnostic issued

Tim Van Holder tim.vanholder@anubex.com
Thu Mar 26 08:40:58 GMT 2020


Relevant package versions (all the current latest):


  *   Cygwin: 3.1.4
  *   binutils: 2.43+1git.de9c1b7cfe-1
  *   gcc-core, gcc-g++, libgcc1, libstdc++6: 9.3.0-1

Sample program (foo.cc):

#include <iostream>

using namespace std;

int
main(void)
{
  cout << "OK" << endl;
  return 0;
}

With a plain g++ foo.cc -o foo, I get a foo.exe that prints "OK".

However, with g++ -gdwarf-5 -Og foo.cc -o foo, I get a binary that reports
 -bash: ./foo.exe: cannot execute binary file: Exec format error
when run.
GDB can load the binary and show symbols just fine, but trying to run results in:
  Error creating process /cygdrive/.../foo.exe, (error 193).

Using -gdwarf-4 instead of -gdwarf-5 or dropping -Og makes the problem go away.
It also seems to be c++-specific; a C version of the sample program resulted in a working program
(could just be because a C++ program with iostream pulls in more, triggering the issue).


More information about the Cygwin mailing list