C structures which are initialized using = { … }; do not execute code,
the init is in place in memory itself for the global.
To avoid having wpp create C++ global objects which need a constructor
called at init, specify -dll in your WPP options. It will change the
global contruction to a c style init using = { … };. This is what
KMDF uses (and no we don’t have any globally constructed c++ objects).
To be complete, you also need to run the global destructors during
unload as well. That requires more CRT implicit magic
d
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jan Bottorff
Sent: Friday, February 24, 2006 10:14 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] DDK 3790 -> WDK 5112
I noticed one of your globals was “CFactoryTemplate g_Templates[1] =
{…};”.
Generally, you get .CRT sections when you have initialized global data
that
needs code to run to initialize it. For example, a global c++ object has
to
have its constructor executed. Is CFactoryTemplate possibly a C++ class?
I
don’t offhand know if there is C syntax that also would required code
execution to initialize. I write a lot of C++ driver code but try hard
to
avoid globally constructed objects. If I can’t avoid them, I add code
like
below and call it early. There is also an article at
http://www.osronline.com/custom.cfm?name=articlePrint.cfm&id=57 that
talks
about this issue (it’s buried among all the info about C++ memory
allocation).
// we have to have the following ugly code to initialize global objects
// Note: WPP used in a CPP file uses global constructors, so we must use
this
typedef void (__cdecl *PVFV)(void);
#pragma data_seg(“.CRT$XCA”)
PVFV __crtXca = { NULL }; // this will be placed by the linker at the
beginning of the list of global constructor functions
#pragma data_seg(“.CRT$XCZ”)
PVFV __crtXcz = { NULL }; // this will be placed by the linker just
past
the end of the list of global constructor functions
#pragma data_seg() // return control to the normal ddk process
#pragma comment(linker, “/merge:.CRT=.data”)
void InitCPPGlobalObjects(void)
{
PVFV * globalConstructor;
globalConstructor = &__crtXca[0];
while (globalConstructor < &__crtXcz[0]) {
if (*globalConstructor) {
(**globalConstructor)();
}
globalConstructor++;
}
}
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-241252-
xxxxx@lists.osr.com] On Behalf Of uwe kirst
Sent: Friday, February 24, 2006 7:09 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] DDK 3790 -> WDK 5112
>Use “link /dump /symbols *.obj > dump.txt” (or link /dump
section:.crt$init
>or whatever the section name is), and then open dump.txt, and see
what is
in
>that section. At least you’ll gain a better understanding of what
the
>compiler and linker are doing, and whether they are doing what you
want
or
>not.
>
>– arlie
>
>
Hello Arlie,
I looked at the dump, but did not find anything. I’m having the
sections:
.bss
.data
.debug$S
.debug$T
.drective
.rdata
.text
There seem to be no .crt section. That’s probably why calling
_crt_init() is also not working.
The .data section contains my global variables:
int g_cTempates;
CFactoryTemplate g_Templates[1] = {…};
Do you know what can cause warning 4210 and how do I find it?
Thanks,
/Uwe
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@pmatrix.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer