473,836 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MC++ Mixed DLLs: how to create pure IL (really) and other issues

Hi folks,

I'm looking at moving a large base of C++ code to .Net under tight time
constraints. The code runs in mission-critical environments, and I am
extremely concerned about the loader lock problem and the potential for
deadlocks.

After pouring over the available information, and trying a few experiments,
I am still left with a few questions and issues I hope someone out there can
shed some light on.

1) Is it even possible to create a DLL using MC++ that is not subject to the
mixed dll/loader lock issue -- or at least. is it actually doable in a
real-world development environment?

To wit: I created a project using the .Net Class Library template and added
a trivial class with a single trivial method.

namespace Test {
class TestClass {
public: int foo() { return(0); }
};
}

I then made sure /noentry was there; removed nochkclr.obj from the link
targets; added the explicit __check_commonl anguageruntime_ version and
_flt_used definitions; and added the SkipVerificatio n attribute -- all per
the instructions on MSDN for creating pure IL Managed C++ assemblies. The
result was still not pure IL; peverify complains about an "unverifiab le PE
header/stub." I searched for the mythical SetILOnly.exe that is also
referenced in MSDN to no avail (even the link to it on MSDN online is
broken). OK, a little research turned up that there's an "IL Only" flag in
the clr header, so I used ildasm and ilasm to reconstitute the assembly with
that flag set. Peverify still complained about "unverifiab le PS
header/stub."

Then I noticed that there was a VTableFixup:

.vtfixup [1] int32 retainappdomain at D_00003004 // 06000001

Why is this? In such a trivial project that is purely managed code? In any
case, manually removing from the il and assembling with ilasm then made the
assembly verify.

So I'm left wondering what all of this means. How can I remove whatever is
causing that fixup to get generated in the first place? And is there
anything I can do as general programming practice to ensure that these don't
creep into my code? And are there other constructs besides vtable fixups
(and unmanaged exports) that could creep into my code that would prevent the
assembly from being pure IL?

2) What actually triggers the loader lock problem -- it can't possibly be
that the DLL is unverifyable. Because C# unsafe code also produces an
unverifiable dll, but which is not subject to the loader lock problem. Is is
the simple absence of the "pure IL" flag in the clr header? Is that enough
to trigger the "mixed" loading behavior where the loader lock problem can
occur?

3) Where is setilonly.exe?

4) Let's say I solve all of the above and produce a dll that really is all
managed code. No CRTs, no unmanaged code, etc. What happens if I then make a
native Win32 API call (note: *not* P/Invoke)? Does that automatically force
me back into being a mixed dll, i.e., can a dll that calls a routine in
kernel32.dll legitimately set the "pure IL" flag in the CLR header?

Thanks for any information that anyone can provide. Note that I am not
interested in debating the likelihood of encountering the loader lock/mixed
dll problem. I am interested in hard facts about how I can use MC++ to
create assemblies that are guaranteed to be 100% free of it, given that I am
willing to forego use of the CRTs and adhere to other restrictive
guidelines.

Thanks!
Nov 16 '05 #1
8 4528
mk
Hi,
Unfortunately it seems as though you're a caught a
little, at least regarding loader lock issues. Its a
known bug, check the following:

http://www.devx.com/DevX/HTML/11470

watch out for word wrap...

http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/dv_vstechart/html/vcconMixedDLLLo adingProblem.as p

You've probably seen this one already, but just in case:

http://www.codeguru.com/cpp_managed/kmg19.html
I find that using a managed core, loading native elements
at runtime can help to ameloriate these issues - sure,
its not exactly a 'pure' solution, but it may help, I
appreciate that you're upgrading pre-existing code, but
some architectural review can be extremely helpful -
assuming you can get the time and the budget.

Hope this helps,

martin
-----Original Message-----
Hi folks,

I'm looking at moving a large base of C++ code to .Net under tight timeconstraints. The code runs in mission-critical environments, and I amextremely concerned about the loader lock problem and the potential fordeadlocks.

After pouring over the available information, and trying a few experiments,I am still left with a few questions and issues I hope someone out there canshed some light on.

1) Is it even possible to create a DLL using MC++ that is not subject to themixed dll/loader lock issue -- or at least. is it actually doable in areal-world development environment?

To wit: I created a project using the .Net Class Library template and addeda trivial class with a single trivial method.

namespace Test {
class TestClass {
public: int foo() { return(0); }
};
}

I then made sure /noentry was there; removed nochkclr.obj from the linktargets; added the explicit __check_commonl anguageruntime_ version and_flt_used definitions; and added the SkipVerificatio n attribute -- all perthe instructions on MSDN for creating pure IL Managed C++ assemblies. Theresult was still not pure IL; peverify complains about an "unverifiab le PEheader/stub." I searched for the mythical SetILOnly.exe that is alsoreferenced in MSDN to no avail (even the link to it on MSDN online isbroken). OK, a little research turned up that there's an "IL Only" flag inthe clr header, so I used ildasm and ilasm to reconstitute the assembly withthat flag set. Peverify still complained about "unverifiab le PSheader/stub."

Then I noticed that there was a VTableFixup:

.vtfixup [1] int32 retainappdomain at D_00003004 // 06000001
Why is this? In such a trivial project that is purely managed code? In anycase, manually removing from the il and assembling with ilasm then made theassembly verify.

So I'm left wondering what all of this means. How can I remove whatever iscausing that fixup to get generated in the first place? And is thereanything I can do as general programming practice to ensure that these don'tcreep into my code? And are there other constructs besides vtable fixups(and unmanaged exports) that could creep into my code that would prevent theassembly from being pure IL?

2) What actually triggers the loader lock problem -- it can't possibly bethat the DLL is unverifyable. Because C# unsafe code also produces anunverifiable dll, but which is not subject to the loader lock problem. Is isthe simple absence of the "pure IL" flag in the clr header? Is that enoughto trigger the "mixed" loading behavior where the loader lock problem canoccur?

3) Where is setilonly.exe?

4) Let's say I solve all of the above and produce a dll that really is allmanaged code. No CRTs, no unmanaged code, etc. What happens if I then make anative Win32 API call (note: *not* P/Invoke)? Does that automatically forceme back into being a mixed dll, i.e., can a dll that calls a routine inkernel32.dll legitimately set the "pure IL" flag in the CLR header?
Thanks for any information that anyone can provide. Note that I am notinterested in debating the likelihood of encountering the loader lock/mixeddll problem. I am interested in hard facts about how I can use MC++ tocreate assemblies that are guaranteed to be 100% free of it, given that I amwilling to forego use of the CRTs and adhere to other restrictiveguidelines.

Thanks!
.

Nov 16 '05 #2
Thanks for the reply -- I was hoping to get commentary from someone "in the
know" about whether I can truly produce pure IL with MC++, whether it's
feasible to maintain a project that does so (given that the compiler doesn't
produce any warnings when you do something that violates "pure il' rules),
and whether calling a Win32 API is a violation of "pure il" rules.

Anyone?

"mk" <mk@nospam.co m> wrote in message
news:03******** *************** *****@phx.gbl.. .
Hi,
Unfortunately it seems as though you're a caught a
little, at least regarding loader lock issues. Its a
known bug, check the following:

http://www.devx.com/DevX/HTML/11470

watch out for word wrap...

http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/dv_vstechart/html/vcconMixedDLLLo adingProblem.as p

You've probably seen this one already, but just in case:

http://www.codeguru.com/cpp_managed/kmg19.html
I find that using a managed core, loading native elements
at runtime can help to ameloriate these issues - sure,
its not exactly a 'pure' solution, but it may help, I
appreciate that you're upgrading pre-existing code, but
some architectural review can be extremely helpful -
assuming you can get the time and the budget.

Hope this helps,

martin
-----Original Message-----
Hi folks,

I'm looking at moving a large base of C++ code to .Net

under tight time
constraints. The code runs in mission-critical

environments, and I am
extremely concerned about the loader lock problem and

the potential for
deadlocks.

After pouring over the available information, and trying

a few experiments,
I am still left with a few questions and issues I hope

someone out there can
shed some light on.

1) Is it even possible to create a DLL using MC++ that

is not subject to the
mixed dll/loader lock issue -- or at least. is it

actually doable in a
real-world development environment?

To wit: I created a project using the .Net Class Library

template and added
a trivial class with a single trivial method.

namespace Test {
class TestClass {
public: int foo() { return(0); }
};
}

I then made sure /noentry was there; removed

nochkclr.obj from the link
targets; added the explicit

__check_commonl anguageruntime_ version and
_flt_used definitions; and added the SkipVerificatio n

attribute -- all per
the instructions on MSDN for creating pure IL Managed

C++ assemblies. The
result was still not pure IL; peverify complains about

an "unverifiab le PE
header/stub." I searched for the mythical SetILOnly.exe

that is also
referenced in MSDN to no avail (even the link to it on

MSDN online is
broken). OK, a little research turned up that there's

an "IL Only" flag in
the clr header, so I used ildasm and ilasm to

reconstitute the assembly with
that flag set. Peverify still complained

about "unverifiab le PS
header/stub."

Then I noticed that there was a VTableFixup:

.vtfixup [1] int32 retainappdomain at D_00003004 //

06000001

Why is this? In such a trivial project that is purely

managed code? In any
case, manually removing from the il and assembling with

ilasm then made the
assembly verify.

So I'm left wondering what all of this means. How can I

remove whatever is
causing that fixup to get generated in the first place?

And is there
anything I can do as general programming practice to

ensure that these don't
creep into my code? And are there other constructs

besides vtable fixups
(and unmanaged exports) that could creep into my code

that would prevent the
assembly from being pure IL?

2) What actually triggers the loader lock problem -- it

can't possibly be
that the DLL is unverifyable. Because C# unsafe code

also produces an
unverifiable dll, but which is not subject to the loader

lock problem. Is is
the simple absence of the "pure IL" flag in the clr

header? Is that enough
to trigger the "mixed" loading behavior where the loader

lock problem can
occur?

3) Where is setilonly.exe?

4) Let's say I solve all of the above and produce a dll

that really is all
managed code. No CRTs, no unmanaged code, etc. What

happens if I then make a
native Win32 API call (note: *not* P/Invoke)? Does that

automatically force
me back into being a mixed dll, i.e., can a dll that

calls a routine in
kernel32.dll legitimately set the "pure IL" flag in the

CLR header?

Thanks for any information that anyone can provide. Note

that I am not
interested in debating the likelihood of encountering

the loader lock/mixed
dll problem. I am interested in hard facts about how I

can use MC++ to
create assemblies that are guaranteed to be 100% free of

it, given that I am
willing to forego use of the CRTs and adhere to other

restrictive
guidelines.

Thanks!
.

Nov 16 '05 #3
http://msdn.microsoft.com/library/en...tilonlybit.asp

http://msdn.microsoft.com/library/en...thmanagedc.asp

check all the points on last list.

Yes, it is possible to produce verifiable image.

"Ted Miller" <te*@nwlink.com > wrote in message
news:vp******** ****@corp.super news.com...
Hi folks,

I'm looking at moving a large base of C++ code to .Net under tight time
constraints. The code runs in mission-critical environments, and I am
extremely concerned about the loader lock problem and the potential for
deadlocks.

After pouring over the available information, and trying a few experiments, I am still left with a few questions and issues I hope someone out there can shed some light on.

1) Is it even possible to create a DLL using MC++ that is not subject to the mixed dll/loader lock issue -- or at least. is it actually doable in a
real-world development environment?

To wit: I created a project using the .Net Class Library template and added a trivial class with a single trivial method.

namespace Test {
class TestClass {
public: int foo() { return(0); }
};
}

I then made sure /noentry was there; removed nochkclr.obj from the link
targets; added the explicit __check_commonl anguageruntime_ version and
_flt_used definitions; and added the SkipVerificatio n attribute -- all per
the instructions on MSDN for creating pure IL Managed C++ assemblies. The
result was still not pure IL; peverify complains about an "unverifiab le PE
header/stub." I searched for the mythical SetILOnly.exe that is also
referenced in MSDN to no avail (even the link to it on MSDN online is
broken). OK, a little research turned up that there's an "IL Only" flag in
the clr header, so I used ildasm and ilasm to reconstitute the assembly with that flag set. Peverify still complained about "unverifiab le PS
header/stub."

Then I noticed that there was a VTableFixup:

.vtfixup [1] int32 retainappdomain at D_00003004 // 06000001

Why is this? In such a trivial project that is purely managed code? In any
case, manually removing from the il and assembling with ilasm then made the assembly verify.

So I'm left wondering what all of this means. How can I remove whatever is
causing that fixup to get generated in the first place? And is there
anything I can do as general programming practice to ensure that these don't creep into my code? And are there other constructs besides vtable fixups
(and unmanaged exports) that could creep into my code that would prevent the assembly from being pure IL?

2) What actually triggers the loader lock problem -- it can't possibly be
that the DLL is unverifyable. Because C# unsafe code also produces an
unverifiable dll, but which is not subject to the loader lock problem. Is is the simple absence of the "pure IL" flag in the clr header? Is that enough
to trigger the "mixed" loading behavior where the loader lock problem can
occur?

3) Where is setilonly.exe?

4) Let's say I solve all of the above and produce a dll that really is all
managed code. No CRTs, no unmanaged code, etc. What happens if I then make a native Win32 API call (note: *not* P/Invoke)? Does that automatically force me back into being a mixed dll, i.e., can a dll that calls a routine in
kernel32.dll legitimately set the "pure IL" flag in the CLR header?

Thanks for any information that anyone can provide. Note that I am not
interested in debating the likelihood of encountering the loader lock/mixed dll problem. I am interested in hard facts about how I can use MC++ to
create assemblies that are guaranteed to be 100% free of it, given that I am willing to forego use of the CRTs and adhere to other restrictive
guidelines.

Thanks!


Nov 16 '05 #4
Thanks for the info.

Click the "Download Sample" link on the SetILOnly sample page -- broken
link. I cannot find this sample or the exe anywhere.

I followed all the points on the last list (except setilonly, which does not
seem to actually exist) -- see my original post. I got an image that still
had vtablefixups.

Also I want to understand the relationship between "verifiable " and
"triggers the mixed dll loading problem".

So does anyone have any info?

Thanks!
"Pent" <pent> wrote in message news:Oz******** ******@tk2msftn gp13.phx.gbl...
http://msdn.microsoft.com/library/en...tilonlybit.asp
http://msdn.microsoft.com/library/en...thmanagedc.asp
check all the points on last list.

Yes, it is possible to produce verifiable image.

"Ted Miller" <te*@nwlink.com > wrote in message
news:vp******** ****@corp.super news.com...
Hi folks,

I'm looking at moving a large base of C++ code to .Net under tight time
constraints. The code runs in mission-critical environments, and I am
extremely concerned about the loader lock problem and the potential for
deadlocks.

After pouring over the available information, and trying a few experiments,
I am still left with a few questions and issues I hope someone out there

can
shed some light on.

1) Is it even possible to create a DLL using MC++ that is not subject to

the
mixed dll/loader lock issue -- or at least. is it actually doable in a
real-world development environment?

To wit: I created a project using the .Net Class Library template and

added
a trivial class with a single trivial method.

namespace Test {
class TestClass {
public: int foo() { return(0); }
};
}

I then made sure /noentry was there; removed nochkclr.obj from the link
targets; added the explicit __check_commonl anguageruntime_ version and
_flt_used definitions; and added the SkipVerificatio n attribute -- all per the instructions on MSDN for creating pure IL Managed C++ assemblies. The result was still not pure IL; peverify complains about an "unverifiab le PE header/stub." I searched for the mythical SetILOnly.exe that is also
referenced in MSDN to no avail (even the link to it on MSDN online is
broken). OK, a little research turned up that there's an "IL Only" flag in the clr header, so I used ildasm and ilasm to reconstitute the assembly

with
that flag set. Peverify still complained about "unverifiab le PS
header/stub."

Then I noticed that there was a VTableFixup:

.vtfixup [1] int32 retainappdomain at D_00003004 // 06000001

Why is this? In such a trivial project that is purely managed code? In any case, manually removing from the il and assembling with ilasm then made

the
assembly verify.

So I'm left wondering what all of this means. How can I remove whatever is causing that fixup to get generated in the first place? And is there
anything I can do as general programming practice to ensure that these

don't
creep into my code? And are there other constructs besides vtable fixups
(and unmanaged exports) that could creep into my code that would prevent

the
assembly from being pure IL?

2) What actually triggers the loader lock problem -- it can't possibly be that the DLL is unverifyable. Because C# unsafe code also produces an
unverifiable dll, but which is not subject to the loader lock problem. Is is
the simple absence of the "pure IL" flag in the clr header? Is that
enough to trigger the "mixed" loading behavior where the loader lock problem can occur?

3) Where is setilonly.exe?

4) Let's say I solve all of the above and produce a dll that really is all managed code. No CRTs, no unmanaged code, etc. What happens if I then

make a
native Win32 API call (note: *not* P/Invoke)? Does that automatically force
me back into being a mixed dll, i.e., can a dll that calls a routine in
kernel32.dll legitimately set the "pure IL" flag in the CLR header?

Thanks for any information that anyone can provide. Note that I am not
interested in debating the likelihood of encountering the loader

lock/mixed
dll problem. I am interested in hard facts about how I can use MC++ to
create assemblies that are guaranteed to be 100% free of it, given that

I am
willing to forego use of the CRTs and adhere to other restrictive
guidelines.

Thanks!


Nov 16 '05 #5
I have SetILOnly source in local msdn install.

You didn't follow ALL the steps outlined in original article.

Because if you did, then you wouldn't have gotten vtfixups.

/clr:initialAppD omain doesn't add vtfixups

"Furthermor e, even DLLs linked with the /noentry option may deadlock on
versions 1.0 and 1.1 of the common language runtime. DLLs linked with the
/noentry option should not deadlock on the next version of the runtime"
http://msdn.microsoft.com/library/en...ingproblem.asp

http://msdn.microsoft.com/msdnmag/is...03/VisualCNET/
"With version 1.1 of the .NET Framework, the vtable includes a flag that
indicates to the runtime that if the call comes into the assembly from
native code, the application domain that's used will be that of the last
application domain used to call into native code. If you look at an assembly
with ILDasm, you'll see that there is a directive to perform the fixups on
the vtable called .vtfixup. For the new behavior, the .vtfixup directive
will have the flag retainappdomain , which is the default when using the /clr
switch."

I've created a simple MC++ .NET library project.

Left all options at its defaults.

Copied your code and added compiler options:

/clr:initialAppD omain /Od

Linker options:

/noentry /fixed:no /opt:ref

Removed nochclr.obj

Added in .cpp file:
#ifdef __cplusplus
extern "C" {
#endif
int _fltused=1;
void _cdecl _check_commonla nguageruntime_v ersion(){}
#ifdef __cplusplus
}
#endif

using namespace System::Securit y::Permissions;
[assembly:Securi tyPermissionAtt ribute(
SecurityAction: :RequestMinimum , SkipVerificatio n=false)];

Then:
Silo.exe -s Test.lib.dll

Then:
peverify TestLib.dll

The result is:
Microsoft (R) .NET Framework PE Verifier Version 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

[MD]: .NET Framework Internal error: 0x8013129d [token:0x0400000 1]
[MD]: .NET Framework Internal error: 0x8013129d [token:0x0600000 1]
All Classes and Methods in testlib.dll Verified
(2 Warnings)

Adding call to win32 api MessageBox doesn't break the verifiability.

All on Visual Studio 2003.

http://support.microsoft.com/?id=814472
"Ted Miller" <te*@nwlink.com > wrote in message
news:vp******** ****@corp.super news.com...
Thanks for the info.

Click the "Download Sample" link on the SetILOnly sample page -- broken
link. I cannot find this sample or the exe anywhere.

I followed all the points on the last list (except setilonly, which does not seem to actually exist) -- see my original post. I got an image that still
had vtablefixups.

Also I want to understand the relationship between "verifiable " and
"triggers the mixed dll loading problem".

So does anyone have any info?

Thanks!
"Pent" <pent> wrote in message news:Oz******** ******@tk2msftn gp13.phx.gbl...

http://msdn.microsoft.com/library/en...tilonlybit.asp

http://msdn.microsoft.com/library/en...thmanagedc.asp

check all the points on last list.

Yes, it is possible to produce verifiable image.

"Ted Miller" <te*@nwlink.com > wrote in message
news:vp******** ****@corp.super news.com...
Hi folks,

I'm looking at moving a large base of C++ code to .Net under tight time constraints. The code runs in mission-critical environments, and I am
extremely concerned about the loader lock problem and the potential for deadlocks.

After pouring over the available information, and trying a few

experiments,
I am still left with a few questions and issues I hope someone out there
can
shed some light on.

1) Is it even possible to create a DLL using MC++ that is not subject
to
the
mixed dll/loader lock issue -- or at least. is it actually doable in a
real-world development environment?

To wit: I created a project using the .Net Class Library template and

added
a trivial class with a single trivial method.

namespace Test {
class TestClass {
public: int foo() { return(0); }
};
}

I then made sure /noentry was there; removed nochkclr.obj from the
link targets; added the explicit __check_commonl anguageruntime_ version and
_flt_used definitions; and added the SkipVerificatio n attribute -- all

per the instructions on MSDN for creating pure IL Managed C++ assemblies. The result was still not pure IL; peverify complains about an "unverifiab le PE
header/stub." I searched for the mythical SetILOnly.exe that is also
referenced in MSDN to no avail (even the link to it on MSDN online is
broken). OK, a little research turned up that there's an "IL Only"
flag
in the clr header, so I used ildasm and ilasm to reconstitute the
assembly with
that flag set. Peverify still complained about "unverifiab le PS
header/stub."

Then I noticed that there was a VTableFixup:

.vtfixup [1] int32 retainappdomain at D_00003004 // 06000001

Why is this? In such a trivial project that is purely managed code? In any case, manually removing from the il and assembling with ilasm then
made the
assembly verify.

So I'm left wondering what all of this means. How can I remove
whatever
is causing that fixup to get generated in the first place? And is there
anything I can do as general programming practice to ensure that these don't
creep into my code? And are there other constructs besides vtable
fixups (and unmanaged exports) that could creep into my code that would prevent the
assembly from being pure IL?

2) What actually triggers the loader lock problem -- it can't possibly

be that the DLL is unverifyable. Because C# unsafe code also produces an
unverifiable dll, but which is not subject to the loader lock problem. Is
is
the simple absence of the "pure IL" flag in the clr header? Is that

enough to trigger the "mixed" loading behavior where the loader lock problem can occur?

3) Where is setilonly.exe?

4) Let's say I solve all of the above and produce a dll that really is all managed code. No CRTs, no unmanaged code, etc. What happens if I then

make
a
native Win32 API call (note: *not* P/Invoke)? Does that automatically

force
me back into being a mixed dll, i.e., can a dll that calls a routine

in kernel32.dll legitimately set the "pure IL" flag in the CLR header?

Thanks for any information that anyone can provide. Note that I am not
interested in debating the likelihood of encountering the loader

lock/mixed
dll problem. I am interested in hard facts about how I can use MC++ to
create assemblies that are guaranteed to be 100% free of it, given

that I
am
willing to forego use of the CRTs and adhere to other restrictive
guidelines.

Thanks!



Nov 16 '05 #6
Dude, you rule. I will try this out. That second link was most helpful!
Thanks!

--

"Pent" <pent> wrote in message news:uT******** *****@TK2MSFTNG P10.phx.gbl...
I have SetILOnly source in local msdn install.

You didn't follow ALL the steps outlined in original article.

Because if you did, then you wouldn't have gotten vtfixups.

/clr:initialAppD omain doesn't add vtfixups

"Furthermor e, even DLLs linked with the /noentry option may deadlock on
versions 1.0 and 1.1 of the common language runtime. DLLs linked with the
/noentry option should not deadlock on the next version of the runtime"
http://msdn.microsoft.com/library/en...ingproblem.asp
http://msdn.microsoft.com/msdnmag/is...03/VisualCNET/
"With version 1.1 of the .NET Framework, the vtable includes a flag that
indicates to the runtime that if the call comes into the assembly from
native code, the application domain that's used will be that of the last
application domain used to call into native code. If you look at an assembly with ILDasm, you'll see that there is a directive to perform the fixups on
the vtable called .vtfixup. For the new behavior, the .vtfixup directive
will have the flag retainappdomain , which is the default when using the /clr switch."

I've created a simple MC++ .NET library project.

Left all options at its defaults.

Copied your code and added compiler options:

/clr:initialAppD omain /Od

Linker options:

/noentry /fixed:no /opt:ref

Removed nochclr.obj

Added in .cpp file:
#ifdef __cplusplus
extern "C" {
#endif
int _fltused=1;
void _cdecl _check_commonla nguageruntime_v ersion(){}
#ifdef __cplusplus
}
#endif

using namespace System::Securit y::Permissions;
[assembly:Securi tyPermissionAtt ribute(
SecurityAction: :RequestMinimum , SkipVerificatio n=false)];

Then:
Silo.exe -s Test.lib.dll

Then:
peverify TestLib.dll

The result is:
Microsoft (R) .NET Framework PE Verifier Version 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

[MD]: .NET Framework Internal error: 0x8013129d [token:0x0400000 1]
[MD]: .NET Framework Internal error: 0x8013129d [token:0x0600000 1]
All Classes and Methods in testlib.dll Verified
(2 Warnings)

Adding call to win32 api MessageBox doesn't break the verifiability.

All on Visual Studio 2003.

http://support.microsoft.com/?id=814472
"Ted Miller" <te*@nwlink.com > wrote in message
news:vp******** ****@corp.super news.com...
Thanks for the info.

Click the "Download Sample" link on the SetILOnly sample page -- broken
link. I cannot find this sample or the exe anywhere.

I followed all the points on the last list (except setilonly, which does not
seem to actually exist) -- see my original post. I got an image that still
had vtablefixups.

Also I want to understand the relationship between "verifiable " and
"triggers the mixed dll loading problem".

So does anyone have any info?

Thanks!
"Pent" <pent> wrote in message

news:Oz******** ******@tk2msftn gp13.phx.gbl...

http://msdn.microsoft.com/library/en...tilonlybit.asp

http://msdn.microsoft.com/library/en...thmanagedc.asp

check all the points on last list.

Yes, it is possible to produce verifiable image.

"Ted Miller" <te*@nwlink.com > wrote in message
news:vp******** ****@corp.super news.com...
> Hi folks,
>
> I'm looking at moving a large base of C++ code to .Net under tight time > constraints. The code runs in mission-critical environments, and I am > extremely concerned about the loader lock problem and the potential for > deadlocks.
>
> After pouring over the available information, and trying a few
experiments,
> I am still left with a few questions and issues I hope someone out there can
> shed some light on.
>
> 1) Is it even possible to create a DLL using MC++ that is not subject to
the
> mixed dll/loader lock issue -- or at least. is it actually doable in
a > real-world development environment?
>
> To wit: I created a project using the .Net Class Library template and added
> a trivial class with a single trivial method.
>
> namespace Test {
> class TestClass {
> public: int foo() { return(0); }
> };
> }
>
> I then made sure /noentry was there; removed nochkclr.obj from the link > targets; added the explicit __check_commonl anguageruntime_ version and > _flt_used definitions; and added the SkipVerificatio n attribute -- all per
> the instructions on MSDN for creating pure IL Managed C++
assemblies.
The
> result was still not pure IL; peverify complains about an "unverifiab le
PE
> header/stub." I searched for the mythical SetILOnly.exe that is also
> referenced in MSDN to no avail (even the link to it on MSDN online

is > broken). OK, a little research turned up that there's an "IL Only"

flag
in
> the clr header, so I used ildasm and ilasm to reconstitute the

assembly with
> that flag set. Peverify still complained about "unverifiab le PS
> header/stub."
>
> Then I noticed that there was a VTableFixup:
>
> .vtfixup [1] int32 retainappdomain at D_00003004 // 06000001
>
> Why is this? In such a trivial project that is purely managed code? In any
> case, manually removing from the il and assembling with ilasm then made the
> assembly verify.
>
> So I'm left wondering what all of this means. How can I remove whatever
is
> causing that fixup to get generated in the first place? And is there
> anything I can do as general programming practice to ensure that
these don't
> creep into my code? And are there other constructs besides vtable

fixups > (and unmanaged exports) that could creep into my code that would prevent the
> assembly from being pure IL?
>
> 2) What actually triggers the loader lock problem -- it can't possibly be
> that the DLL is unverifyable. Because C# unsafe code also produces
an > unverifiable dll, but which is not subject to the loader lock problem.
Is
is
> the simple absence of the "pure IL" flag in the clr header? Is that

enough
> to trigger the "mixed" loading behavior where the loader lock
problem can
> occur?
>
> 3) Where is setilonly.exe?
>
> 4) Let's say I solve all of the above and produce a dll that really
is all
> managed code. No CRTs, no unmanaged code, etc. What happens if I
then make
a
> native Win32 API call (note: *not* P/Invoke)? Does that

automatically force
> me back into being a mixed dll, i.e., can a dll that calls a routine

in > kernel32.dll legitimately set the "pure IL" flag in the CLR header?
>
> Thanks for any information that anyone can provide. Note that I am not > interested in debating the likelihood of encountering the loader
lock/mixed
> dll problem. I am interested in hard facts about how I can use MC++ to > create assemblies that are guaranteed to be 100% free of it, given

that
I
am
> willing to forego use of the CRTs and adhere to other restrictive
> guidelines.
>
> Thanks!
>
>



Nov 16 '05 #7
Thanks again for taking the time to reply. I was finally able to locate the
source for silo.exe. However I'm afraid calling Win32 APIs does in fact
break verifiability and I guess forces a mixed dll.

x.h:

#include <windows.h>
using namespace System;
namespace Test {
public __gc class Class1 {
int TestMethod(int i) { return(i); }
};
}

x.cpp

#include "t.h"
extern "C" {
int _fltused=1;
void __cdecl _check_commonla nguageruntime_v ersion(){}
}

using namespace System::Securit y::Permissions;
[assembly:Securi tyPermissionAtt ribute(
SecurityAction: :RequestMinimum , SkipVerificatio n=false)];

Make /noentry, add /clr:initialAppD omain, /opt:ref, /fixed:no etc as per the
instructions.

Then silo -s x.dll, the image verifies (thanks for the help!!!).

But: now change TestMethod to

int TestMethod(int i) { MessageBoxW(NUL L,L"",L"",0); return(i); }

Then silo -s x.dll. PEVerify says

[IL]: Error: Unverifiable PE Header/native stub
[IL]: Error: Unverifiable image '' can not be run
2 Errors Verifying debug\x.dll

Sigh. Sadly I think I am forced to C# (with unsafe code and p/invoke as
necessary) -- just cannot risk triggering the deadlock due to the mixed dll
problem.

"Pent" <pent> wrote in message news:uT******** *****@TK2MSFTNG P10.phx.gbl...
I have SetILOnly source in local msdn install.

You didn't follow ALL the steps outlined in original article.

Because if you did, then you wouldn't have gotten vtfixups.

/clr:initialAppD omain doesn't add vtfixups

"Furthermor e, even DLLs linked with the /noentry option may deadlock on
versions 1.0 and 1.1 of the common language runtime. DLLs linked with the
/noentry option should not deadlock on the next version of the runtime"
http://msdn.microsoft.com/library/en...ingproblem.asp
http://msdn.microsoft.com/msdnmag/is...03/VisualCNET/
"With version 1.1 of the .NET Framework, the vtable includes a flag that
indicates to the runtime that if the call comes into the assembly from
native code, the application domain that's used will be that of the last
application domain used to call into native code. If you look at an assembly with ILDasm, you'll see that there is a directive to perform the fixups on
the vtable called .vtfixup. For the new behavior, the .vtfixup directive
will have the flag retainappdomain , which is the default when using the /clr switch."

I've created a simple MC++ .NET library project.

Left all options at its defaults.

Copied your code and added compiler options:

/clr:initialAppD omain /Od

Linker options:

/noentry /fixed:no /opt:ref

Removed nochclr.obj

Added in .cpp file:
#ifdef __cplusplus
extern "C" {
#endif
int _fltused=1;
void _cdecl _check_commonla nguageruntime_v ersion(){}
#ifdef __cplusplus
}
#endif

using namespace System::Securit y::Permissions;
[assembly:Securi tyPermissionAtt ribute(
SecurityAction: :RequestMinimum , SkipVerificatio n=false)];

Then:
Silo.exe -s Test.lib.dll

Then:
peverify TestLib.dll

The result is:
Microsoft (R) .NET Framework PE Verifier Version 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

[MD]: .NET Framework Internal error: 0x8013129d [token:0x0400000 1]
[MD]: .NET Framework Internal error: 0x8013129d [token:0x0600000 1]
All Classes and Methods in testlib.dll Verified
(2 Warnings)

Adding call to win32 api MessageBox doesn't break the verifiability.

All on Visual Studio 2003.

http://support.microsoft.com/?id=814472
"Ted Miller" <te*@nwlink.com > wrote in message
news:vp******** ****@corp.super news.com...
Thanks for the info.

Click the "Download Sample" link on the SetILOnly sample page -- broken
link. I cannot find this sample or the exe anywhere.

I followed all the points on the last list (except setilonly, which does not
seem to actually exist) -- see my original post. I got an image that still
had vtablefixups.

Also I want to understand the relationship between "verifiable " and
"triggers the mixed dll loading problem".

So does anyone have any info?

Thanks!
"Pent" <pent> wrote in message

news:Oz******** ******@tk2msftn gp13.phx.gbl...

http://msdn.microsoft.com/library/en...tilonlybit.asp

http://msdn.microsoft.com/library/en...thmanagedc.asp

check all the points on last list.

Yes, it is possible to produce verifiable image.

"Ted Miller" <te*@nwlink.com > wrote in message
news:vp******** ****@corp.super news.com...
> Hi folks,
>
> I'm looking at moving a large base of C++ code to .Net under tight time > constraints. The code runs in mission-critical environments, and I am > extremely concerned about the loader lock problem and the potential for > deadlocks.
>
> After pouring over the available information, and trying a few
experiments,
> I am still left with a few questions and issues I hope someone out there can
> shed some light on.
>
> 1) Is it even possible to create a DLL using MC++ that is not subject to
the
> mixed dll/loader lock issue -- or at least. is it actually doable in
a > real-world development environment?
>
> To wit: I created a project using the .Net Class Library template and added
> a trivial class with a single trivial method.
>
> namespace Test {
> class TestClass {
> public: int foo() { return(0); }
> };
> }
>
> I then made sure /noentry was there; removed nochkclr.obj from the link > targets; added the explicit __check_commonl anguageruntime_ version and > _flt_used definitions; and added the SkipVerificatio n attribute -- all per
> the instructions on MSDN for creating pure IL Managed C++
assemblies.
The
> result was still not pure IL; peverify complains about an "unverifiab le
PE
> header/stub." I searched for the mythical SetILOnly.exe that is also
> referenced in MSDN to no avail (even the link to it on MSDN online

is > broken). OK, a little research turned up that there's an "IL Only"

flag
in
> the clr header, so I used ildasm and ilasm to reconstitute the

assembly with
> that flag set. Peverify still complained about "unverifiab le PS
> header/stub."
>
> Then I noticed that there was a VTableFixup:
>
> .vtfixup [1] int32 retainappdomain at D_00003004 // 06000001
>
> Why is this? In such a trivial project that is purely managed code? In any
> case, manually removing from the il and assembling with ilasm then made the
> assembly verify.
>
> So I'm left wondering what all of this means. How can I remove whatever
is
> causing that fixup to get generated in the first place? And is there
> anything I can do as general programming practice to ensure that
these don't
> creep into my code? And are there other constructs besides vtable

fixups > (and unmanaged exports) that could creep into my code that would prevent the
> assembly from being pure IL?
>
> 2) What actually triggers the loader lock problem -- it can't possibly be
> that the DLL is unverifyable. Because C# unsafe code also produces
an > unverifiable dll, but which is not subject to the loader lock problem.
Is
is
> the simple absence of the "pure IL" flag in the clr header? Is that

enough
> to trigger the "mixed" loading behavior where the loader lock
problem can
> occur?
>
> 3) Where is setilonly.exe?
>
> 4) Let's say I solve all of the above and produce a dll that really
is all
> managed code. No CRTs, no unmanaged code, etc. What happens if I
then make
a
> native Win32 API call (note: *not* P/Invoke)? Does that

automatically force
> me back into being a mixed dll, i.e., can a dll that calls a routine

in > kernel32.dll legitimately set the "pure IL" flag in the CLR header?
>
> Thanks for any information that anyone can provide. Note that I am not > interested in debating the likelihood of encountering the loader
lock/mixed
> dll problem. I am interested in hard facts about how I can use MC++ to > create assemblies that are guaranteed to be 100% free of it, given

that
I
am
> willing to forego use of the CRTs and adhere to other restrictive
> guidelines.
>
> Thanks!
>
>



Nov 16 '05 #8
"Ted Miller" wrote in message news:vp******** ****@corp.super news.com...
However I'm afraid calling Win32 APIs does in fact
break verifiability and I guess forces a mixed dll.
I don't know for sure, maybe someone from MS will comment later.

[...] Sigh. Sadly I think I am forced to C# (with unsafe code and p/invoke as
necessary) -- just cannot risk triggering the deadlock due to the mixed dll problem.


That's what i would do given that you don't need to link in any
crt/clibs/etc
to your assembly. I think Win32 API is pretty doable with dllimport.
Assuming
you don't need tons of it.

Hmm i tried:
int TestMethod(int i) { MessageBoxW(NUL L,L"",L"",0); return(i); }
But it still verifies.

Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1718
by: Steve Terepin | last post by:
I've found some rather worrying articles (Mixed Mode Library Assembly bug, Richard Grimes, Windows Developer Network Sept 2003 ; and Knowledge Base Article 814472 ) that point out the need to use the /noentry switch and an explicit initialisation procedure, to be able to safely use Managed C++ assemblies that call down into standard C library functions. Could someone confirm that I've understood this properly ? I'm writing some Managed...
9
2595
by: Edward Diener | last post by:
I received no answers about this the first time I posted, so I will try again. My inability to decipher an MSDN topic may find others who have the same inability and someone who can decipher and explain it. I have some questions about the instructions for creating a mixed mode DLL in the MSDN topic "Converting Managed Extensions for C++ Projects from Pure Intermediate Language to Mixed Mode" in the "Managed Extensions for C++ Reference"....
4
5573
by: bonk | last post by:
This article http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmex/html/vcconconvertingmanagedextensionsforcprojectsfrompureintermediatelanguagetomixedmode.asp seems to be somewhat out of date. Not all of it seem to apply to vs 2005 (beta 2) and c++/CLI. I followed the instructions given there but using vs 2005 beta 2 I get some warnings about depreciation: warning CRT1001: _vcclrit.h is deprecated warning C4996:...
0
3232
by: ZMan | last post by:
Scenario: This is about debugging server side scripts that make calls to middle-tier business DLLs. The server side scripts are legacy ASP 3.0 pages, and the DLLs are managed DLLs converted/developed with VB.NET. What I want from debugging is to be able to step into the methods in the DLLs called from ASP scripts using Visual Studio .NET. Background: For typical script debugging issues, you can read and follow the two documents on...
2
1505
by: Ubergeek | last post by:
I recently came accross an article that stated that there were unresolved issued with calling native (i.e. "unmanaged" C++) from managed C++. Does anyone know what the precise details of this issue is, and if there have been any fixes/workarounds yet?. I am using C# (VC7.1) for my frontend, but all my logic is tied up in Win32 C (and some C++) dlls. If I understand the issue correctly, so long as I compile the native C/C++ Dlls with...
8
2212
by: WebSnozz | last post by:
I have an application written in C that does a lot of low level stuff. It does a lot of things like casting from void*'s. I want to create a new GUI for it in either C# or MC++, but reuse the existing code. The options I've considered so far: 1. Create a new MC++ GUI project and add the *.c files to them and mark them with pragma unamanged. However, the /clr option does not compile *.c files, so I rename them to *.cpp, and now they...
1
6293
by: =?Utf-8?B?RmFiaWFu?= | last post by:
Hello, I want to give multiple native classes (in different mixed mode dlls) access to a managed output window (for error messages). Therefore I wrote a native singleton with __declspec (dllexport). I get the following compiler errors: Error 224 error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe Error 225 error C4394: 'ErrorHandler::instance' : per-appdomain symbol should not be marked with...
1
1304
by: Jerome | last post by:
Hi all, I've made a .NET wrapper of a C++ toolkit using MC++ (perhaps I should now take a look to C++/CLI). The 32 bits version works fine on Win32 and 64 bits version works fine on Win64 .... but .... 32 bits version fails to run under 64 bits (the C++ 32 bits version works well). In fact a FileNotFoundException is thrown at startup ... no way to get rid of it !
5
2798
by: =?Utf-8?B?aWduaGVucnk=?= | last post by:
I have a managed C++ project and two C# projects. All are class library projects. The C++ project links with native C++ static libraries and references to one C# project. The projects structure goes something like this. Proj2_MCPP --(references)--Proj1_CSharp Proj3_CSharp --(references)--Proj2_MCPP and Proj1_CSharp My objective is to link the DLLs produced by the 3 projects into a single DLL. I tried the following scenario.
0
9671
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10551
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10595
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6979
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5650
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5828
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4021
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.