Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Unable to open cygwin.S' shows up at a certain value for a variable

My program runs a finite element method on a 2D grid. The code works fine for grids smaller than 195x195, but whenever I try to make it bigger the following is shown:

Unable to open 'cygwin.S': Unable to read file 'c:\mingw810\src\gcc-8.1.0\libgcc\config\i386\cygwin.S' (Error: Unable to resolve non-existing file 'c:\mingw810\src\gcc-8.1.0\libgcc\config\i386\cygwin.S').

I tried to put a breakpoint in the very beggining to check where the problem is, but it does not work because the issue shows up before the breakpoint. I guess it has something to do with the compiler and the memory since the problem pops up at a certain size of the grid. I am not putting the code in here as it is too big and it involves few files, but the way I am creating the pointers is:

int *pivot_N;

I am using:

g++ (x86_64-win32-seh-rev0, Built by MinGW-W64 project) 8.1.0

I have 52 variables, 16 of them are pointers. Could the problem be that I have too many variables? I have not a lot of experience, but also tried to run it on a higher RAM computer just in case, and the problem persists.

like image 446
bnp38 Avatar asked Jan 25 '23 16:01

bnp38


1 Answers

I think it's a "stack overflow" issue. It is related to memory allocation in C++. For variables inside a function (main(), for example), their size cannot exceed the "stack" size. The "stack" size is probably determined by the compiler or the OS. Typically the stack size is just 1 MB, 2 MB or so.

I run into the same issue when debugging using MinGW-w64's gdb in VScode on Windows. When the array size is too big, like 600,000 elements, I tried to run the exe, but it terminated quickly. So I debugged it, and it showed "cygwin.S" not found or something similar. The debugger probably knows the memory size to be used before the main() function starts. I think the compiler should know that as well, but it generates the executable anyway.

Another thing about "cygwin.S" "missing" is that the debugger tries to find the source code file where the issue occurs. But the compiler we are using is not from source code but rather pre-built library/executable (I'm not sure if I'm using the right terminology) by others, so the .S source code file is not there from the beginning.

My solution to my code was to use global variable instead, i.e. put the array declaration before main() function. But the proper way to do it might be "dynamic memory allocation". That is to properly allocate large memory on "heap" memory rather than on "stack" memory. If simply putting large variables outside any function doesn't suit your purpose, you should look into that.

like image 142
Qm Zhang Avatar answered Jan 27 '23 06:01

Qm Zhang