Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can massive nested loops cause the linker to run endlessly when compiling in Release-Mode?

I'm compiling a very small Win32 command-line application in VS2010 Release-Mode, with all speed optimizations turned on (not memory optimizations).

This application is designed to serve a single purpose - to perform a single pre-defined complex mathematical operation to find a complex solution to a specific problem. The algorithm is completely functional (confirmed) and it compiles and runs fine in Debug-Mode. However, when I compile in Release-Mode (the algorithm is large enough to make use of the optimizations), Link.exe appears to run endlessly, and the code never finishes linking. It sits at 100% CPU usage, with no changes in memory usage (43,232 K).

My application contains only two classes, both of which are pretty short code files. However, the algorithm comprises 20 or so nested loops with inline function calls from within each layer. Is the linker attempting to run though every possible path through these loops? And if so, why is the Debug-Mode linker not having any problems?

This is a tiny command-line application (2KB exe file), and compiling shouldn't take more than a couple minutes. I've waited 30 minutes so far, with no change. I'm thinking about letting it link overnight, but if it really is trying to run through all possible code paths in the algorithm it could end up linking for decades without a SuperComputer handy.

What do I need to do to get the linker out of this endless cycle? Is it possible for such code to create an infinite link-loop without getting a compiler-error prior to the link cycle?

EDIT:
Jerry Coffin pointed out that I should kill the linker and attempt again. I forgot to mention this in the original post, but I have aborted the build, closed and re-opened VS, and attempted to build multiple times. The issue is consistent, but I haven't changed any linker options as of yet.
EDIT2:
I also neglected to mention the fact that I deleted the "Debug" and "Release" folders and re-built from scratch. Same results.
EDIT3:
I just confirmed that turning off function inlining causes the linker to function normally. The problem is I need function inlining, as this is a very performance-sensitive operataion with a minimal memory footprint. This leads me to ask, why would inlining cause such a problem to occur?
EDIT4:
The output that displays during the unending link cycle:

Link:
  Generating code

EDIT5:
I confirmed that placing all the code into a single CPP file did not resolve the issue.

like image 624
Giffyguy Avatar asked Feb 28 '11 06:02

Giffyguy


3 Answers

Nested loops only affect the linker in terms of Link Time Code Generation. There's tons of options that determine how this works in detail.

For a start I suggest disabling LTCG alltogether to see if there's some other unusual problem.

If it links fine in Release with LTCG disabled you can experiment with inlining limits, intrinsics and optimization level.

like image 60
COrthbandt Avatar answered Oct 02 '22 12:10

COrthbandt


Have you done a rebuild? If one of the object files got corrupted, or a .ilk file (though release mode probably isn't using one, I can't be sure about your project settings), then the cleaning pass which rebuild does should cure it.

Closing and re-opening Visual Studio is only helpful in cases when the debugging (or one of the graphical designers) is keeping an open handle to the build product.

Which leads to another suggestion -- check Task Manager and make sure that you don't have a copy of your application still running.

like image 21
Ben Voigt Avatar answered Oct 02 '22 10:10

Ben Voigt


If the linker seems to be the bottle neck and both classes are pretty short, why not put all the code in a single file? Also, there is a multi-processor compilation option in visual studio under C++ general tab in the project settings dialog box. Both of these might help.

like image 35
Samsdram Avatar answered Oct 02 '22 12:10

Samsdram