“pure virtual function called” on gcc 4.4 but not on newer version or clang 3.4

后端 未结 2 521
孤街浪徒
孤街浪徒 2021-01-04 08:05

I\'ve got an MCVE which, on some of my machines crashes when compiled with g++ version 4.4.7 but does work with clang++ version 3.4.2 and g++ version 6.3.

I\'d like

相关标签:
2条回答
  • 2021-01-04 08:27

    This is a Red Hat-specific bug not present in FSF GCC. It is not a problem in your code.

    On a system with both CentOS 6's GCC, and FSF GCC 4.4.7, having both generate an assembly listing and viewing the differences between the two, one bit jumps out:

    CentOS 6's GCC generates

    movq $_ZTV8BaseType+16, (%rsp)
    

    whereas FSF GCC 4.4.7 generates

    movq $_ZTV11TypeTextFix+16, (%rsp)
    

    In other words, one of Red Hat's GCC patches makes it set up the vtable incorrectly. This is part of your main function, you can see it in your own assembly listing shortly after .L48:.

    Red Hat applies many patches to its version of GCC, and some of them are patches that affect code generation. Unfortunately, one of them appears to have an unintended side effect.

    0 讨论(0)
  • 2021-01-04 08:27

    Though the true solution to this bug would be not to use RedHat GnuCC 4.4.7 (or any RedHat compiler...), we are temporarily stuck with this version.

    We did find an alternative: obfuscate the constructor of BaseType to the compiler hence preventing it to over-optimize it. We did it simply by defining BaseType::BaseType() in a separate translation unit.

    Doing so bypass g++ bug. We did indeed checked that both BaseType and TypeTextFix virtual table pointers were written to constructed object before calling its related constructors.

    0 讨论(0)
提交回复
热议问题