From: Vincent Fatica on
With VC7 I'm accustomed to using custom a custom entry point and avoiding the
CRT altogether. I get no complaints from the compiler or linker and I get small
EXEs and DLLs that work properly.

How do I build the same code with VC8 and avoid the .CRT section and warnings
such as these.

LIBCMT.lib(mathfcns.obj) : warning LNK4210: .CRT section exists; there may be
unhandled static initializers or terminators
LIBCMT.lib(cpu_disp.obj) : warning LNK4210: .CRT section exists; there may be
unhandled static initializers or terminators

Those warnings coming from calls to __chkstk and __memset and I can get rid of
them by getting rid of the likes of the following (which occur **inside**
functions).

WCHAR szStr1[4096] = L"foo"; (invokes __memset)

WCHAR szStr2[32768]; (invokes __chkstk)

Is there some fundamental difference between VC7 and VC8 that makes these simple
tasks require such a fuss? And what does the .CRT section do? It's only 8
bytes? Can I make VC8 act like VC7 in this respect?

P.S. been here (this forum) before about this and didn't get satisfactory
answers.
--
- Vince
From: Alex Blekhman on
"Vincent Fatica" wrote:
> How do I build the same code with VC8 and avoid the .CRT section
> and warnings such as these.

First of all you should disable default linking with CRT
libraries. Go to project settings and in Linker category set
Ignore All Deafault Libraries to Yes (/NODEFAULTLIB linker
switch).

> Those warnings coming from calls to __chkstk and __memset and I
> can get rid of them by getting rid of the likes of the following
> (which occur **inside** functions).
>
> WCHAR szStr1[4096] = L"foo"; (invokes __memset)
>
> WCHAR szStr2[32768]; (invokes __chkstk)

In order to get rid of security checks that compiler injects into
you code you should specify /GS- and /Gs- switches. Also, you can
turn stack checks off with this pragma:

#pragma check_stack(off)

In order to prevent `__memset' injection you can try to disable
compiler intrinsics with /Oi- switch.

HTH
Alex




From: Vincent Fatica on
On Wed, 20 Aug 2008 11:35:50 +0300, "Alex Blekhman" <tkfx.REMOVE(a)yahoo.com>
wrote:

>> How do I build the same code with VC8 and avoid the .CRT section
>> and warnings such as these.
>
>First of all you should disable default linking with CRT
>libraries. Go to project settings and in Linker category set
>Ignore All Deafault Libraries to Yes (/NODEFAULTLIB linker
>switch).
>
>> Those warnings coming from calls to __chkstk and __memset and I
>> can get rid of them by getting rid of the likes of the following
>> (which occur **inside** functions).
>>
>> WCHAR szStr1[4096] = L"foo"; (invokes __memset)
>>
>> WCHAR szStr2[32768]; (invokes __chkstk)
>
>In order to get rid of security checks that compiler injects into
>you code you should specify /GS- and /Gs- switches. Also, you can
>turn stack checks off with this pragma:
>
>#pragma check_stack(off)
>
>In order to prevent `__memset' injection you can try to disable
>compiler intrinsics with /Oi- switch.

I already had /GS-. With all your other suggestions I now get:

error LNK2019: unresolved external symbol __chkstk referenced in function "void
__cdecl GetHelp(long)" (?GetHelp@@YAXJ@Z)
error LNK2019: unresolved external symbol _memset referenced in function "void
__cdecl GetHelp(long)" (?GetHelp@@YAXJ@Z)

As for .CRT, I hex-edited its contents to make all 8 bytes 0. The DLL worked
fine. Does it do anything?
--
- Vince
From: Vincent Fatica on
On 20 Aug 2008 08:08:26 -0400, Vincent Fatica <vince(a)blackholespam.net> wrote:

>On Wed, 20 Aug 2008 11:35:50 +0300, "Alex Blekhman" <tkfx.REMOVE(a)yahoo.com>
>wrote:
>
>>> How do I build the same code with VC8 and avoid the .CRT section
>>> and warnings such as these.
>>
>>First of all you should disable default linking with CRT
>>libraries. Go to project settings and in Linker category set
>>Ignore All Deafault Libraries to Yes (/NODEFAULTLIB linker
>>switch).
>>
>>> Those warnings coming from calls to __chkstk and __memset and I
>>> can get rid of them by getting rid of the likes of the following
>>> (which occur **inside** functions).
>>>
>>> WCHAR szStr1[4096] = L"foo"; (invokes __memset)
>>>
>>> WCHAR szStr2[32768]; (invokes __chkstk)
>>
>>In order to get rid of security checks that compiler injects into
>>you code you should specify /GS- and /Gs- switches. Also, you can
>>turn stack checks off with this pragma:
>>
>>#pragma check_stack(off)
>>
>>In order to prevent `__memset' injection you can try to disable
>>compiler intrinsics with /Oi- switch.
>
>I already had /GS-. With all your other suggestions I now get:
>
>error LNK2019: unresolved external symbol __chkstk referenced in function "void
>__cdecl GetHelp(long)" (?GetHelp@@YAXJ@Z)
>error LNK2019: unresolved external symbol _memset referenced in function "void
>__cdecl GetHelp(long)" (?GetHelp@@YAXJ@Z)

/Gs- didn't work, but /Gs200000 got rid of the __chkstk messages but I still
have the __memset problem.
--
- Vince
From: Alex Blekhman on
"Vincent Fatica" wrote:
> /Gs- didn't work, but /Gs200000 got rid of the __chkstk messages
> but I still have the __memset problem.

Maybe if you implement __memset by yourself, then it will go away.

Is there any reason that you want to avoid CRT? The linker is
pretty good and will be able to eliminate dead code anyway. It is
only several KB.

Alex