升级到G ++ 4.8 - exception_ptr.h不支持异常传播 [英] Upgrading to G++ 4.8 - exception_ptr.h Does not support exception propagation

查看:501
本文介绍了升级到G ++ 4.8 - exception_ptr.h不支持异常传播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用g ++ 4.8重新编译一个巨大的遗留应用程序,以调试 glibc检测到的内存损坏问题(使用AddressSanitizer)。



以前我们使用过g ++ 4.4.7。



/opt/rh/devtoolset-2/root/usr/include/c++/4.8.2/bits/exception_ptr.h:40:4:error:#error此平台不支持异常传播。



编译自定义异常处理程序(我猜)。自定义异常处理程序仅在一处使用 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'\\\
,s.c_str());
mErrorReporter(0,DvLog :: WARNING,0,Dv :: NO_PROFILE,0,DvLog :: UNHANDLED_OTHER_EXCEPTION);

reportOtherException()是这样使用的:

  try 
{
//捕获并记录未捕获的异常,然后退出。
catch(const std :: bad_exception& e){exHandler.reportBadException(e); }
catch(const std :: exception& e){exHandler.reportStandardException(e); }
catch(...){exHandler.reportOtherException(); }
}

我对C ++很陌生,不知道错误是什么甚至意味着。

任何需要更改以在4.8上进行编译的指针?


$使用4.4.7并且不适用于4.8。 b $ b

编辑我



以下是一些额外信息:

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

最小编码

DvComDefaultExceptionHandler_test.h

  #includeDvCommon.h
#includeevt / DvEvt.h
#includelog / DvLog.h
#includecom / 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

  #includeDvCommon.h
#includecom / DvComDefaultExceptionHandler_test.h


//指向DvComDefaultExceptionHandler类的单个实例。
const DvComDefaultExceptionHandler *
DvComDefaultExceptionHandler :: mpInstance = 0;

编译命令和输出

  g ++ -c -g -O0 -DDEBUG -Wall -Wextra -Wno-sign-compare -Wcast-align 
--template-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
在从../../include/com/DvComDefaultExceptionHandler_test.h:76:0包含的文件中,从DvComDefaultExceptionHandler_test.cpp获得
:13:
/ opt / rh / devtoolset-2 / root / usr / include / c ++ / 4.8.2 / bits / exception_ptr.h:40:4:error:#error此平台不支持异常传播。
#错误此平台不支持异常传播。

编辑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);

$ / code>

G ++ VERSION:

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

编辑II



我用g ++ 6.3.1 ,运行在Centos 7虚拟机上。仍然是同样的问题。

源文件 - 仅限一行

  #include< bits / exception_ptr.h> 

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

解决方案

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

在GCC 7中,这个问题已经被修正(再次意外),作为这个bug的一部分:



包含< bits / exception_ptr.h>



这意味着您的选择是:


  1. 使用C ++ 11或更高版本模式编译代码(建议使用C ++ 14,建议使用GCC 6)。
  2. 使用GCC 7升级到DTS 7 if当它变得可用时,它有上游修复程序,可以重新启用C ++ 98 hack。 使用 std :: exception_ptr 为不透明类型,在C ++ 11或更高版本模式下编译它的实现,并保留t他在C ++ 98模式下的系统其余部分。
  3. 使用另一种黑客,或许就像这样:

      #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)。



I'm trying to recompile a huge legacy app with g++ 4.8 in order debug a glibc detected memory corruption problem (using AddressSanitizer). Previously we used g++ 4.4.7.

However, compilation fails with:

/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.

while compiling a custom exception handler (I guess). The custom exception handler uses exception_ptr in only one place:

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);
}

And reportOtherException() is used like this:

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();     }
}

I'm pretty new to C++ and don't know what the error even means. Worked with 4.4.7 and doesn't work with 4.8.

Any pointers on what needs to be changed to compile on 4.8?

EDIT I

Here's some additional info:

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

Minimum Code

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;

Compile command and output

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

Tracing through the include files comes down to the value of __GCC_ATOMIC_INT_LOCK_FREE. Running this simple program prints '2' as the value for __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

I've tried it with g++ 6.3.1, running on a Centos 7 VM. Still the same problem.

Source File - one line only

#include <bits/exception_ptr.h>

Compile command: g++ -c -o test.o test.cpp

解决方案

First of all, including <bits/exception_ptr.h> directly is technically unsupported. It says so right in the header file. This worked in GCC 4.4 by more or less by accident. The C++11 migration of this header file broke it because for namespace reasons, C++98 code cannot use the ATOMIC_INT_LOCK_FREE macro, and the header does not work anymore.

In GCC 7, this was fixed (again accidentally) as part of this bug:

The trick to include <bits/exception_ptr.h> directly should work again in this version.

This means that your options are:

  1. Compile your code in C++11 or later mode (C++14 with GCC 6 recommended).
  2. Upgrade to DTS 7 with GCC 7 if and when it becomes available, which has the upstream fix which re-enables the C++98 hack.
  3. Wrap the use of std::exception_ptr in an opaque type, compile its implementation in C++11 or later mode, and keep the rest of the system in C++98 mode.
  4. Use another hack, perhaps like this one:

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

    Again, this is completely unsupported, but it should not be any worse than what you have today (with GCC 4.4).

这篇关于升级到G ++ 4.8 - exception_ptr.h不支持异常传播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆