[wdmaudiodev] Re: Link errors in build using native math functions

  • From: Tim Roberts <timr@xxxxxxxxx>
  • To: wdmaudiodev@xxxxxxxxxxxxx
  • Date: Thu, 22 Apr 2010 10:56:22 -0700

Dibyendu Nandy wrote:
>
> The library is built separately and then linked with other libraries
> to get the audio driver. I am getting the following errors in the link
> stage. Does anyone have an idea why there should be link conflicts,
> why should native math library functions have conflicts
> with libcntpr.lib and ntstrsafe.lib. I tried an experiment using IPP
> calls to replace all the calls to sqrt(), but I still get the same errors.
>
> Would appreciate your responses and any fix for this issue.
>
> -- LINK ERRORS --
> 1>...\libcntpr.lib(sqrt.obj) : error LNK2005: __CIsqrt already defined
> in ntoskrnl.lib(ntoskrnl.exe)
> 1>...\libcntpr.lib(sin.obj) : error LNK2005: __CIsin already defined
> in ntoskrnl.lib(ntoskrnl.exe)
> 1>...\libcntpr.lib(cos.obj) : error LNK2005: __CIcos already defined
> in ntoskrnl.lib(ntoskrnl.exe)
> 1>...\ntstrsafe.lib(ftol2.obj) : error LNK2005: __ftol2 already
> defined in libcntpr.lib(ftol2.obj)
>
> I should add that the sources file includes the following DDK libraries.

The last issue is a subtle one, and only occurs with XP builds. 
Something in one of the libraries is using SSE, and making a reference
to _ftol2_sse.  Libcntpr.lib defines _ftol2, but does not define
_ftol2_sse, but the ntstrsafe module that includes _ftol2_sse also
includes _ftol2.  You can work around this by adding the following C
source file to your driver:

    #include <wdm.h>
    #ifdef _M_IX86
    #if OSVER(NTDDI_VERSION) == NTDDI_WINXP
    extern long __cdecl _ftol2();
    long __declspec(naked) __cdecl _ftol2_sse()
    {
        __asm jmp _ftol2
    }
    #endif
    #endif

Remember that you have to be careful to save and restore the floating
point state every request that uses floating point.  Is IPP guaranteed
to work in kernel code?  Are the XMM registers saved in the context?

-- 
Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.

Other related posts: