T
Ted Miller
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_commonlanguageruntime_version and
_flt_used definitions; and added the SkipVerification 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 "unverifiable 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 "unverifiable 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!
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_commonlanguageruntime_version and
_flt_used definitions; and added the SkipVerification 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 "unverifiable 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 "unverifiable 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!