Unable to run files build with debugging information (-g option) with mingw on windows 11 after upgrading to version 2.24.0
I am running windows 11. I am using the TDM-GCC-64 compiler. After upgrading to the latest version 2.24.0, I am unable to run programs which are built with debugging information (-g option) while getting a "Access is denied" message. Binaries built without this option continue to run perfectly.
A very simple example
#include <SDL2\SDL.h>
int main(int argc, char* argv[]) {
SDL_Init(SDL_INIT_VIDEO);
SDL_Quit();
return 0;
}
> gcc -g minimum-sdl2.c -lmingw32 -lsdl2main -lSDL2
> a.exe
Access is denied.
Are you able to use git bisect to find out where this broke?
I can reproduce this by downloading and installing tdm64-gcc-10.3.0-2.exe from https://jmeubank.github.io/tdm-gcc/.
Linking to the MinGW SDL2 sdk gives the following error on Windows 10:

When I link to the VC SDK, the executable runs just fine. You can link to .lib files by using full paths.
When I modify the code to the following, the executable builds and runs fine
#define SDL_MAIN_HANDLED
#include "SDL.h"
#include <stdio.h>
int main(int argc, char* argv[]) {
SDL_Init(SDL_INIT_VIDEO);
SDL_Quit();
printf("If you are reading this then nothing went wrong.\n");
return 0;
}
Also noteworthy, my issue also happens when building in release mode (without -g).
Building SDL2 myself with TDM, and linking to its libraries also works perfectly So it's really only the MinGW binary SDK release that is giving us/you troubles.
If I build with mingw using gcc 10.3.0, I get this issue. If I build with mingw using gcc 11.3.0, the executables work fine. The 2.0.22 binaries were built with gcc 11.1.0, and the 2.24.0 binaries were built with gcc 12.1.0, so it seems like it's an issue where gcc 12 binaries can't be linked using gcc 10.
Unfortunately I upgraded to gcc 12 because of a code generation issue in gcc 11 which caused a crash in SDL_ttf.
Let me think about this...
Actually, it's not quite that simple. The 2.24.0 libSDL2main.a works with mingw gcc version 10.2.0, so it's not strictly a gcc version issue.
This is the problem: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101377
The newer binutils uses -gdwarf-5 by default, which is broken in the earlier versions of binutils used by TDM and others. I can work around this by passing -gdwarf-4 in the command line options when building the release archive.