Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#17403 closed defect (fixed)

Crash under Windows XP with DLLs built with MSVC 2015

Reported by: mirh_ Owned by: Vadim Zeitlin <vadim@…>
Priority: normal Milestone:
Component: wxMSW Version: 3.0.2
Keywords: WinXP TLS DLL Cc:
Blocked By: Blocking:
Patch: no

Description

This bug should directly follow #13116, and you can read some other background here.

Actual workaround consists in using /Zc:threadSafeInit- compiler switch to build the project.
Do you know if this has and can have any downside, or would it be possible to find a better solution?

Thank you.

Change History (16)

comment:1 Changed 4 years ago by vadz

  • Status changed from new to confirmed
  • Summary changed from MSVC 2015 brings back Thread Local Storage access violation to Crash under Windows XP with DLLs built with MSVC 2015

It should be safe to use /Zc:threadSafeInit- as we don't rely on static initialization being thread-safe anywhere just because this isn't the case with non-C++11 compilers.

If you, or anybody else interested in XP support, can make (and test!) the change doing it in the project files (ideally in just build/msw/wx_config.props to avoid modifying all of them which risks being tricky knowing that they're used for all MSVS 201x versions while this option probably exists only for 2015) and submit a patch with your changes, I would apply it.

TIA!

comment:2 follow-up: Changed 4 years ago by awi

You can experiment with modifying wx_setup.props file this way:

  • build/msw/wx_setup.props

    diff --git a/build/msw/wx_setup.props b/build/msw/wx_setup.props
    a b  
    7171    <Link>
    7272      <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;comdlg32.lib;winspool.lib;shell32.lib;shlwapi.lib;ole32.lib;oleaut32.lib;uuid.lib;advapi32.lib;version.lib;comctl32.lib;rpcrt4.lib;wsock32.lib;wininet.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
    7373    </Link>
     74    <ClCompile>
     75      <AdditionalOptions Condition="'$(VisualStudioVersion)' == '14.0'">/Zc:threadSafeInit- %(AdditionalOptions)</AdditionalOptions>
     76    </ClCompile>
    7477  </ItemDefinitionGroup>
    7578  <ItemGroup>
    7679    <BuildMacro Include="wxShortVersionString">
     
    101104      <Value>$(wxIntRootDir)</Value>
    102105    </BuildMacro>
    103106  </ItemGroup>
    104 </Project>
     107</Project>

This setting can be seen in GUI in Configuration Properties -> C/C++ -> All Options -> Additional Options.

comment:3 Changed 4 years ago by vadz

Thanks awi, this is exactly what I had in mind.

We also should change the toolkits here to have "_xp" suffixes, see #17386.

If mirh_ can confirm that the above change works, I could still commit it in time for 3.1.0.

comment:4 Changed 4 years ago by mirh_

The file in pcsx2 is called Common.props, for the records.

Anyway yes, that line fixes it!
Thank you.

comment:5 Changed 4 years ago by vadz

I don't understand the file name remark. You need to modify the file wx_setup.props in wxWidgets itself to rebuild the library with this compiler flag.

comment:6 Changed 4 years ago by mirh_

I know, but at the moment I have this Wx problem inside a project that compiles against that proprieties file. :s

It's fine now.

comment:7 Changed 4 years ago by mirh_

Any news?
I guess it would perfectly follow #17408

comment:8 Changed 4 years ago by mirh_

Any chance for this in 3.0.3 or 3.1.1?

comment:9 in reply to: ↑ 2 Changed 4 years ago by mirh_

<AdditionalOptions Condition="'$(PlatformToolset)' == 'v$(PlatformToolsetVersion)_xp'">/Zc:threadSafeInit- %(AdditionalOptions)</AdditionalOptions>

I just tested this, and I guess it would be even neater.

Last edited 4 years ago by mirh_ (previous) (diff)

comment:10 Changed 4 years ago by mirh_

After reading this, I wonder if a check for _ATL_XP_TARGETING shouldn't be added here.

Also -given that-, a very thorough workaround for the issue in this ticket would control something more "specific" to XP support.
Like the aforementioned preprocessor definition plus the "standard" _USING_V110_SDK71_

Or perhaps.. is there any way to check /SUBSYSTEM minimum required version?

comment:11 Changed 4 years ago by vadz

I don't think _ATL_XP_TARGETING is relevant for us, surely it can only do anything when actually using ATL (which is not our case)? I think testing for _USING_V110_SDK71_ should be enough, am I missing anything?

If not, I can merge your PR after just removing this test.

comment:12 Changed 4 years ago by mirh_

Well, quite surprisingly it seems they even build GUIs over ATL..
Albeit it's not like I expect somebody doing it nowadays, with wx (I mean, especially if nobody complained in all these years).

Still, I abandoned the idea of conditionally checking prepocessor defines (I really wouldn't know how) and I just stuck with -basically- the solution proposed by awi.
Once abandoned that idea (and fully aware there would still be a hypothetical ATL vs2015 wx rare circumstance not covered) adding the ifdef ATL seemed a quite innocent sop.

comment:13 Changed 4 years ago by Vadim Zeitlin <vadim@…>

  • Owner set to Vadim Zeitlin <vadim@…>
  • Resolution set to fixed
  • Status changed from confirmed to closed

In 26a58e9d484a9fbbd000dff3e49e570f2bafd417/git-wxWidgets:

Don't use thread-safe statics with MSVS when targeting XP

Disable thread-safe initialization for static local variables in Visual Studio
2015 when XP toolset is used as this results in crashes when using DLLs under
XP, see #13116.

Closes #17403.

comment:14 Changed 4 years ago by vadz

Sorry, I still don't understand why should we check for ATL in our headers, if "they" use ATL, they surely don't use wxWidgets at the same time.

So I've applied the toolset check part, but didn't add this check, please reopen if this is really a problem in practice. Thanks!

comment:15 Changed 4 years ago by mirh_

In practice it should just be a problem for whoever madman wanted to support XP with W8 SDK.. But I see the point in not supporting not supported fringe stuff.

comment:16 Changed 4 years ago by Vadim Zeitlin <vadim@…>

In 2a21297d4169321581a4b942531bbca6e1b65775/git-wxWidgets:

Don't use thread-safe statics with MSVS when targeting XP

Disable thread-safe initialization for static local variables in Visual Studio
2015 when XP toolset is used as this results in crashes when using DLLs under
XP, see #13116.

See #17403.

See https://github.com/wxWidgets/wxWidgets/pull/305

(cherry picked from commit 26a58e9d484a9fbbd000dff3e49e570f2bafd417)

Note: See TracTickets for help on using tickets.