2017-07-30 81 views
1

我试图用g ++ 4.8重新编译一个巨大的遗留应用程序,以便调试glibc detected memory corruption问题(使用AddressSanitizer)。以前我们使用g ++ 4.4.7。升级到G ++ 4.8 - exception_ptr.h不支持异常传播

但是,编译失败:

/opt/rh/devtoolset-2/root/usr/include/c++/4.8.2/bits/exception_ptr.h:40:4: error: #error This platform does not support exception propagation.

在编译自定义异常处理程序(我猜)。自定义异常处理程序只在一个地方使用exception_ptr

void reportOtherException(void) const 
{ 
    std::exception_ptr p = std::current_exception(); 
    std::string s = (p != 0 ? p.__cxa_exception_type()->name() : "null"); 

    printf("DvMain Bad Exception: '%s'\n", s.c_str()); 
    mErrorReporter(0, DvLog::WARNING, 0, Dv::NO_PROFILE, 0, DvLog::UNHANDLED_OTHER_EXCEPTION); 
} 

而且reportOtherException()这样使用:

try 
{ 
    // Catch and log uncaught exceptions, then exit. 
    catch (const std::bad_exception& e) { exHandler.reportBadException(e);  } 
    catch (const std::exception& e)  { exHandler.reportStandardException(e); } 
    catch (...)       { exHandler.reportOtherException();  } 
} 

我很新的C++,不知道是什么错误,即使手段。使用4.4.7并且不适用于4.8。

什么需要改变什么指针来编译4.8?

编辑我

下面是一些额外的信息:

g++ --version 
g++ (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15) 

最小码

DvComDefaultExceptionHandler_test.h

#include "DvCommon.h" 
#include "evt/DvEvt.h" 
#include "log/DvLog.h" 
#include "com/DvComErrorReporter.h" 

#include <new> 
#include <exception> 
#include <sys/time.h> 
#include <sys/resource.h> 
#include <stdlib.h> 
#include <unistd.h> 
#include <malloc.h> 
#include <bits/exception_ptr.h> 

class DvComDefaultExceptionHandler 
{ 
public: 
    DvComDefaultExceptionHandler(const DvComErrorReporter& er) {} 
    ~DvComDefaultExceptionHandler() { } 

    void reportOtherException(void) const 
    { 
     std::exception_ptr p = std::current_exception(); 
    } 

private: 

    static const DvComDefaultExceptionHandler* mpInstance; 
}; 

DvComDefaultExceptionHandler_test.cpp

#include "DvCommon.h" 
#include "com/DvComDefaultExceptionHandler_test.h" 


// Pointer to the single instance of the DvComDefaultExceptionHandler class. 
const DvComDefaultExceptionHandler* 
DvComDefaultExceptionHandler::mpInstance = 0; 

编译命令和输出

g++ -c -g -O0 -DDEBUG -Wall -Wextra -Wno-sign-compare -Wcast-align 
--ftemplate-depth-32 -march=native -ggdb -fPIC -Iinclude -I../../include 
-I../../src -I/usr/include/libxml2 -D_GNU_SOURCE 
-I/mnt/swdevel/DVMon/source_build/ext/ACE -D__ACE_INLINE__ 
-I/usr/local/include -I/usr/lib/qt-3.3/include 
-o DvComDefaultExceptionHandler.o DvComDefaultExceptionHandler_test.cpp 
In file included from ../../include/com/DvComDefaultExceptionHandler_test.h:76:0, 
       from DvComDefaultExceptionHandler_test.cpp:13: 
/opt/rh/devtoolset-2/root/usr/include/c++/4.8.2/bits/exception_ptr.h:40:4: error: #error This platform does not support exception propagation. 
# error This platform does not support exception propagation. 

EDIT II

跟踪通过包括文件归结为__GCC_ATOMIC_INT_LOCK_FREE的值。运行这个简单的程序打印'2'作为__GCC_ATOMIC_INT_LOCK_FREE的值。

int 
main(int argc, char **argv) 
{ 
    printf("__GCC_ATOMIC_INT_LOCK_FREE = %d\n", __GCC_ATOMIC_INT_LOCK_FREE); 
} 

G ++ VERSION:

$ g++ --version 
g++ (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15) 

EDIT II

我已经与克++ 6.3.1尝试过,上一个CentOS 7 VM上运行。仍然是同样的问题。

源文件 - 一个行仅

#include <bits/exception_ptr.h> 

编译命令:g++ -c -o test.o test.cpp

+0

我无法在Red Hat Enterprise Linux 6.9上用DTS 2重现这一点。请用'devtoolset-2-gcc-C++'软件包版本来修改你的文章,一个简单的例子(它可能是一些'#include'指令触发的)和完整的编译器命令行。 –

+0

你用-std = C++ 11编译过吗? – 2017-07-30 16:17:54

+0

我已更新最低代码。我没有与std = C++ 11编译,相同的标志为4.4.7 – Danny

回答

0

首先,包括<bits/exception_ptr.h>直接在技术上不受支持。它在头文件中说得很对。这在GCC 4.4中或多或少意外地工作。这个头文件的C++ 11迁移破坏了它,因为对于名称空间的原因,C++ 98代码不能使用ATOMIC_INT_LOCK_FREE宏,并且头不再工作。

在GCC 7,这是固定的(再次意外),因为这错误的一部分:

诀窍包括<bits/exception_ptr.h>直接应在此版本重新工作。

这意味着你的选项是:

  1. 编译在C++ 11或更高模式的代码(C++使用GCC 6 14推荐)。
  2. 使用GCC 7升级到DTS 7时,如果它变得可用,它具有重新启用C++ 98 hack的上游修复程序。
  3. std::exception_ptr用于不透明类型,在C++ 11或更高版本模式下编译它的实现,并将系统的其余部分保留在C++ 98模式下。
  4. 使用另一个黑客,也许像这样的:

    #include <exception> 
    #ifndef ATOMIC_INT_LOCK_FREE 
    # define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE 
    #endif 
    #include <bits/exception_ptr.h> 
    

    再次,这是完全不支持,但它不应该有任何比你有什么今天(使用GCC 4.4)差。

+0

谢谢!我会尝试#4黑客。我只想运行Address Sanitizer,4.8是最接近版本的版本。即使从4.4.7到4.8,也有很多新的错误/警告需要理清。转向C++ 11将会是一项巨大的工作 - 可能几个月。这是一个相当大的应用程序。 – Danny

0

我能够重现使用dockerized Centos6您的问题,用gcc 4.8.2。将开发工具升级到版本6(gcc 6.3.1)后,您的代码编译时没有任何问题。尝试升级使用这些步骤开发工具(建议仅用于测试):

[testing-devtools] 
name=devtools multiple for CentOS 
baseurl=http://mirror.centos.org/centos/6/sclo/x86_64/rh/ 
gpgcheck=0 

  • 通过添加文件/etc/yum.repos.d/devtools-sclo.repo添加sclo centos6库

  • 安装devtoolset-6包:

    百胜安装devtoolset -6-的binutils devtoolset -6- GCC-C++

  • 集的bash环境,新的版本:

    SCL使devtoolset-6的bash

现在尝试重新编译你的基地例如和完整的源代码。

注意:同一个存储库还包含devtoolset-3和devtoolset-4的软件包。如果需要,很容易尝试。

+0

感谢您查看它。如另一个问题所述,升级devtools并不起作用。该说明仅适用于64位,似乎没有32位回购可用(?) – Danny

+0

我创建了一个新的Centos 7 64位虚拟机。我试过g ++ 4.8,5.3和6.3.1。所有都有相同的错误。 cpp文件现在只有一行:'#include '。你是如何得到它的工作? – Danny

+0

@丹尼此标题不能直接包含。查看其内容。首先尝试包括。 – pe3k