cef3.xp兼容编译的一个大坑

本文介绍了一个关于Chrome浏览器在Windows XP系统下遇到的崩溃问题及其解决方案。问题出现在使用特定版本源码编译的Chrome中加入了MP3支持后,在XP系统上运行时遇到异常。通过详细的调试与分析,最终发现问题是由于线程安全静态变量初始化导致,并通过调整编译选项/Zc:threadSafeInit-成功解决了该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 现象:

chrome源码3.2623.1397.gaf139d7加入mp3支持,在win7下很稳定。在xp下崩溃无法运行。

解决过程:

1.加入调试语句,发现只要碰到函数static变量,就会崩溃。例如以下代码

void AddInternalSchemes(std::vector<std::string>* standard_schemes,
                        std::vector<std::string>* savable_schemes) {
  // chrome: and chrome-devtools: schemes are registered in
  // RenderThreadImpl::RegisterSchemes().
  // Access restrictions for chrome-extension: and chrome-extension-resource:
  // schemes will be applied in CefContentRendererClient::WillSendRequest

    //qsy 
DLOG(INFO) << "test crashed";
  static CefContentClient::SchemeInfo schemes[2] = {
    { extensions::kExtensionScheme,         true,  true,  false, false },
    { extensions::kExtensionResourceScheme, true,  true,  false, false },
  };

    //qsy 
DLOG(INFO) << "no crashed";
2.尝试在CEF_INITIALIZE函数也加这个类型的static赋值,一样碰到赋值语句就崩溃,底下语句都没有执行。

3.不断的尝试,不断的猜想,百思不得其解,尝试了3天。于是各种请教搜索引擎,历时2天,搜索yahoo.关键字

xp static variable exception

得出这篇

http://stackoverflow.com/questions/32517234/access-violation-on-static-initialization

这篇指出:

Windows Server 2003 and Windows XP have problems with dynamically loading a DLL (via LoadLibrary) that uses thread-local storage, which is what thread-safe statics use internally to provide efficient execution when the static local has already been initialized. As these systems are out of support, it is extremely unlikely for a patch to be created for those systems to add this support as is present in Vista and newer OSes, and we are reluctant to penalize the performance on in-support OSes to provide this functionality to the old out-of-support ones.

To work around the issue you can use /Zc:threadSafeInit- to disable the thread-safe initialization code and this will avoid the thread-local variable. Of course by doing so the initialization code reverts back to the VS2013 mode and is not thread-safe, so this option is only viable if you don't rely on the thread-safety of local statics.


为了解决这个问题可以加入编译选项:/Zc:threadSafeInit-


修改源码chromium\src\build\common.gypi

3238行为:'Common_Base':
在3300行加入::'/Zc:threadSafeInit-',

附近代码为:

['OS=="win" and MSVS_VERSION == "2015"', {
            'msvs_settings': {
              'VCCLCompilerTool': {
                'AdditionalOptions': [
                  # Work around crbug.com/526851, bug in VS 2015 RTM compiler.
                  '/Zc:sizedDealloc-',
 '/Zc:threadSafeInit-',
                ],
              },
            },
          }],

再次重新编译。

重新编译后,xp总算可以正常运行了.





评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值