简体   繁体   English

std :: shared_ptr与MSVC在另一台计算机上崩溃?

[英]std::shared_ptr crash with MSVC on different computer?

Compiling and running the following simple program works fine on my developer machine (Visual Studio 2015, 64-bit). 在我的开发人员机器(Visual Studio 2015,64位)上,编译并运行以下简单程序可以正常工作。

Running the same code on a different machine crashes with the windows error dialog, even though the x64-redistributables are installed (msvcp140.dll): 即使安装了x64-redistributables(msvcp140.dll),在其他计算机上运行相同的代码也会因Windows错误对话框而崩溃:

#include <memory>
#include <iostream>

int main(int argc, char **argv) {
  std::shared_ptr<int> test; // comment out to run on both machines

  std::cout << "Done: " << std::endl;
}

Removing the line with the shared pointer makes it work. 使用共享指针删除该行即可正常工作。

Any idea what the problem could be here, or how to debug? 知道这里可能存在什么问题或如何调试吗?

I found the problem, in case this is useful for anyone: 我发现了问题,以防万一这对任何人都有用:

In the windows event viewer, I discovered the reason for the crash: The exception was 0xc000001d or illegal instruction . 在Windows事件查看器中,我发现了崩溃的原因:异常是0xc000001dillegal instruction Appareantly my code was compiled using the /arch:AVX compile flag, resulting in the following code for the snippet above: 显然,我的代码是使用/arch:AVX compile标志进行编译的,导致上面的代码段包含以下代码:

int main(int argc, char **argv) {
00007FF749A816B0  sub         rsp,48h  
00007FF749A816B4  mov         qword ptr [rsp+20h],0FFFFFFFFFFFFFFFEh  
00007FF749A816BD  vpxor       xmm0,xmm0,xmm0  
00007FF749A816C1  vmovdqu     xmmword ptr [test],xmm0  
  std::shared_ptr<int> test; // comment out to run on both machines

  std::cout << "Done: " << std::endl;
00007FF749A816C7  lea         rdx,[string "Done: " (07FF749A86C70h)]  
00007FF749A816CE  mov         rcx,qword ptr [__imp_std::cout (07FF749A8A0D8h)]  
00007FF749A816D5  call        std::operator<<<std::char_traits<char> > (07FF749A8107Dh)  
  ...

As you can see, because of the /arch:AVX the vpxor and vmovdqu instructions were generated, which do not run on processors that are too old (like the one I tested with). 如您所见,由于/arch:AVXvpxor ,生成了vpxorvmovdqu指令,它们无法在过旧的处理器(例如我测试过的处理器)上运行。

The solution is to have separate versions of the executable (or separate paths through the program) with and without AVX instructions to support older processors. 解决方案是具有可执行文件的单独版本(或程序的单独路径),并带有和不带有AVX指令以支持较早的处理器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM