Linking takes upto an hour

R

Ram Shriram

My C++ project takes 45-60 minutes for linking, with link.exe taking up 100%
of the CPU.

I am using:
Microsoft Visual Studio 2005
Version 8.0.50727.42 (RTM.050727-4200)

Microsoft Visual C++ 2005 77626-009-0000007-41789
Microsoft Visual C++ 2005

The same code links with gcc and SunStudio compilers in less than 30
seconds.

I have enabled incremental linking for the project.

Here is the link time log:
Linking...
LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/LTCG' specification
Creating library C:\Ram\prj\prj.lib and object C:\Ram\prj\prj.exp
LibDef: Total time = 0.000s
Generating code
Finished generating code
OptRef: Total time = 0.000s
OptIcf: Total time = 0.063s
Pass 1: Interval #1, time = 1548.766s
Pass 2: Interval #2, time = 3.640s
Final: Total time = 1552.406s
Embedding manifest...
LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/LTCG' specification
Creating library C:\Ram\prj\prj.lib and object C:\Ram\prj\prj.exp
LibDef: Total time = 0.016s
Generating code
Finished generating code
OptRef: Total time = 0.000s
OptIcf: Total time = 0.047s
Pass 1: Interval #1, time = 2013.203s
Pass 2: Interval #2, time = 1.297s
Final: Total time = 2014.500s


I do know which piece of code is triggering it - I am allocating a 20,000
byte buffer on the stack in a particular function:
void function() {
...
BYTE ba[] = { (BYTE) 0x11, (BYTE) 0x42, ... ... ... };
...
}


If I #ifdef this code out, the link times return to less than a minute.

Any suggestions ?

Thanks,
RS
 
B

Ben Voigt [C++ MVP]

I do know which piece of code is triggering it - I am allocating a 20,000
byte buffer on the stack in a particular function:
void function() {
...
BYTE ba[] = { (BYTE) 0x11, (BYTE) 0x42, ... ... ... };
...
}


If I #ifdef this code out, the link times return to less than a minute.

Any suggestions ?

Yeah, put that function in a separate library without /LTCG so it never gets
recompiled.
 
C

Carl Daniel [VC++ MVP]

Ben said:
I do know which piece of code is triggering it - I am allocating a
20,000 byte buffer on the stack in a particular function:
void function() {
...
BYTE ba[] = { (BYTE) 0x11, (BYTE) 0x42, ... ... ... };
...
}


If I #ifdef this code out, the link times return to less than a
minute. Any suggestions ?

Yeah, put that function in a separate library without /LTCG so it
never gets recompiled.

But /LTCG is a linker command, the OP need the compiler equivalent: Put that
function in a separate compiland and compile it with /GL- to inhibit link
time code generation for that module.

-cd
 
N

Nikolaos D. Bougalis

Ram said:
I do know which piece of code is triggering it - I am allocating a 20,000
byte buffer on the stack [...]

Setting aside the linking issue, I can't help but wonder why on earth
you would want to allocate such a huge buffer on the stack? I cannot
think of any sane reason.

If you don't need to modify the buffer, then why not simply declare it
static const?

If you do need to modify the buffer, then why not declare a single
static const copy of the buffer, and then dynamically allocate a chunk
of memory when needed, and memcpy the contents of the static buffer into
it, use it and then release it.

-n
 
N

Nikolaos D. Bougalis

Ram said:
I do know which piece of code is triggering it - I am allocating a 20,000
byte buffer on the stack [...]

Setting aside the linking issue, I can't help but wonder why on earth
you would want to allocate such a huge buffer on the stack? I cannot
think of any sane reason.

If you don't need to modify the buffer, then why not simply declare it
static const?

If you do need to modify the buffer, then why not declare a single
static const copy of the buffer, and then dynamically allocate a chunk
of memory when needed, and memcpy the contents of the static buffer into
it, use it and then release it.

-n
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top