Menu

#158 TLS callback problem with /MT and static library

v1.1.x
closed
5
2015-01-20
2013-02-06
SamKu
No

I used vs2005 to build an static library of log4cplus-1.1.1-rc(2,3) with /MT configuration. When I run unit test program, it always shows:

  runtime error R6030
  - CRT not initialized

But this error doesn't show when I use log4cplus-1.1.1-rc1 with /MT.

I did some diff to find the problem. The root cause is log4cplus used TLS callback since rc2 (global-init.cxx). And it seems to not support well when build with /MT.

I found a related web page for this:
http://stackoverflow.com/questions/14538159/about-tls-callback-in-windows

BTW, use vs2012 to build with /MT also has another crash problem, the callstack shows:

        ....REPEAT
    ntdll.dll!_KiUserExceptionDispatcher@8()   Unknown
    bb40e64e()  Unknown
    appender_test.exe!__crtFlsGetValue(unsigned long dwFlsIndex) Line 394   C
    appender_test.exe!_getptd_noexit() Line 277 C
    appender_test.exe!_getptd() Line 337    C
    appender_test.exe!__InternalCxxFrameHandler(EHExceptionRecord * pExcept, EHRegistrationNode * pRN, _CONTEXT * pContext, void * pDC, const _s_FuncInfo * pFuncInfo, int CatchDepth, EHRegistrationNode * pMarkerRN, unsigned char recursive) Line 337    C++
    appender_test.exe!__CxxFrameHandler3(EHExceptionRecord * pExcept, EHRegistrationNode * pRN, void * pContext, void * pDC) Line 355   C++
    ntdll.dll!ExecuteHandler2@20() Unknown
    ntdll.dll!ExecuteHandler@20()  Unknown
    ntdll.dll!_RtlDispatchException@8()    Unknown
    ntdll.dll!_KiUserExceptionDispatcher@8()   Unknown
    bb40e64e()  Unknown
    appender_test.exe!__crtFlsGetValue(unsigned long dwFlsIndex) Line 394   C
    appender_test.exe!_getptd_noexit() Line 277 C
    appender_test.exe!_getptd() Line 337    C
    appender_test.exe!__InternalCxxFrameHandler(EHExceptionRecord * pExcept, EHRegistrationNode * pRN, _CONTEXT * pContext, void * pDC, const _s_FuncInfo * pFuncInfo, int CatchDepth, EHRegistrationNode * pMarkerRN, unsigned char recursive) Line 337    C++
    appender_test.exe!__CxxFrameHandler3(EHExceptionRecord * pExcept, EHRegistrationNode * pRN, void * pContext, void * pDC) Line 355   C++
    ntdll.dll!ExecuteHandler2@20() Unknown
    ntdll.dll!ExecuteHandler@20()  Unknown
    ntdll.dll!_RtlDispatchException@8()    Unknown

I am not familiar with TLS callback, but I think it should not be used with library is not a DLL.

Discussion

  • Václav Haisman

    Václav Haisman - 2013-02-06

    TBH, I am inclined to mark this as 'not a bug' or 'won't fix' because /MT or /MTd is not one of supported configurations. It is either that or forcing everybody to initialize log4cplus in main() through log4cplus::initializeLog4cplus().

    Let me think about it a little bit more, though.

     
  • Václav Haisman

    Václav Haisman - 2013-02-06
    • labels: --> tls, windows
    • assigned_to: Václav Zeman
     
  • Václav Haisman

    Václav Haisman - 2013-02-12

    I have committed a change to both trunk and 1.1.x branch that makes log4cplus complain loudly during compilation if you do not use DLL C run time library. I do not think there is any other better way to do this.

     
  • Václav Haisman

    Václav Haisman - 2013-02-27
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,6 +1,9 @@
    -I used vs2005 to build an static library of log4cplus-1.1.1-rc(2,3) with /MT configuration . When I run unit test program, it always shows:
    +I used vs2005 to build an static library of log4cplus-1.1.1-rc(2,3) with /MT configuration. When I run unit test program, it always shows:
    +
    +~~~~
       runtime error R6030
       - CRT not initialized
    +~~~~
    
     But this error doesn't show when I use log4cplus-1.1.1-rc1 with /MT.
    
    @@ -11,7 +14,7 @@
    
     BTW, use vs2012 to build with /MT also has another crash problem, the callstack shows:
    
    -
    +~~~~
             ....REPEAT
        ntdll.dll!_KiUserExceptionDispatcher@8
     () Unknown
    @@ -41,5 +44,6 @@
     () Unknown
        ntdll.dll!_RtlDispatchException@8
     () Unknown
    +~~~~
    
     I am not familiar with TLS callback, but I think it should not be used with library is not a DLL.
    
     
  • Václav Haisman

    Václav Haisman - 2013-05-27
    • labels: tls, windows --> tls, windows, v1.1.1
    • status: open --> closed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.