简体   繁体   English

c ++ app崩溃在非AVX CPU上

[英]c++ app crashing on non AVX CPUs

I have an AVX optimized app which I do not need to make compatible with non AVX CPUs. 我有一个AVX优化的应用程序,我不需要与非AVX CPU兼容。 However, I would like to display a clean error dialog on these older CPUs, rather than having the app crashing, as that causes customer confusion. 但是,我想在这些较旧的CPU上显示一个干净的错误对话框,而不是让应用程序崩溃,因为这会导致客户混淆。

In my main() I create the QApplication instance (I'm using the Qt framework), then test for AVX using gcc __builtin_cpu_supports ("avx") . 在我的main()我创建了QApplication实例(我使用的是Qt框架),然后使用gcc __builtin_cpu_supports ("avx")测试AVX。 If it fails, I display an error dialog. 如果失败,我会显示错误对话框。 This proved to work on non-AVX CPUs on a simple test app. 事实证明这适用于简单测试应用程序上的非AVX CPU。

However, our (large) application crashes before displaying the dialog box on non AVX CPUs. 但是,我们的(大型)应用程序在非AVX CPU上显示对话框之前崩溃。

I have suspected: 我怀疑:

  • Global variable initialization somewhere which uses AVX intrinsics. 使用AVX内在函数的某处的全局变量初始化。 I'm not 100% sure to have checked everywhere, but it seems this is not the case. 我不是百分百肯定到处检查过,但似乎情况并非如此。
  • gcc optimizer uses AVX instructions on some code called before the check. gcc优化器在检查前调用的某些代码上使用AVX指令。

Problem is, I have no non-AVX system at work for debugging and I would prefer avoiding purchasing one if possible. 问题是,我没有非AVX系统正在进行调试,如果可能,我宁愿避免购买。

  1. Is it possible to disable AVX when debugging on my CPU so that debugger stops on any AVX instruction? 在我的CPU上调试时是否可以禁用AVX,以便调试器在任何AVX指令上停止?
  2. Any alternative ideas? 还有其他想法吗?

You could create a (non-optimised) wrapper program that performs the feature test, then either exits with a friendly message or execs your application. 您可以创建一个(非优化的)包装器程序来执行功能测试,然后通过友好消息退出或执行您的应用程序。

The QApplication constructor is allowed to modify the passed arguments, so you'll need to take a copy (or not use any Qt in the path that goes through to exec() ). 允许QApplication构造函数修改传递的参数,因此您需要获取一个副本(或者不要在通过exec()的路径中使用任何Qt)。

Something like (from my head): 像(从我的头上):

int main(int argc, char **argv)
{
    if (__builtin_cpu_supports ("avx")) {
        execv("/the/real/program", argv);
        perror("exec");
        exit 1;
    } else {
        QApplication app(argc, argv);
        QDialog d;
        d.show();
        return 1;
    }
}

VMWare can fake the CPUID of the guest OS, and you could just turn off all AVX bits. VMWare可以伪造客户操作系统的CPUID ,您可以关闭所有AVX位。

However, this is just lying to the application : it won't cause the app to break into the debugger if it still executes that AVX instruction. 但是,这只是骗应用程序:如果仍然执行该AVX指令,它将不会导致应用程序进入调试器。

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

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