AIX 5.3 上跨共享库问题的异常

发布于 2024-12-05 03:23:31 字数 6309 浏览 4 评论 0原文

我正在为 AIX 移植一个非常稳定的代码,该代码已经在 Windows、Linux(32 位和 64 位)以及 Solaris SPARC 和 x86 中运行。该代码在共享库中抛出异常:

Environment: IBM AIX 5.3 64 Bits
Compiler: GCC 4.6.1

注意:该问题发生在以 32 位或 64 位编译的代码上

该架构有点复杂,但基本上我们有: CoreModules.a:静态库,包含共享库使用的所有核心函数、对象和结构。异常类在这里定义,异常由这里定义的类抛出。使用$(AR)生成。

libConfig.so:包含配置信息的共享库。链接到 CoreModules.a。此处定义的类引发异常。

libHostServices.so:包含业务规则的共享库。链接到 CoreModules.alibConfig.so。此处定义的类引发异常。

下面是我的编译和链接选项:

export CXX=g++
export MODE=debug
if [ "$OBJECT_MODE" -eq 64 ]
then 
    export CXXFLAGS="-g -v -W -Wall -fPIC -O2 -mminimal-toc -fpermissive -fexceptions -Wmissing-field-initializers -Wwrite-strings -Wformat -maix64"
else 
    export CXXFLAGS="-g -v -W -Wall -fPIC -O2 -mminimal-toc -fpermissive -fexceptions -Wmissing-field-initializers -Wwrite-strings -Wformat"
export LDFLAGS=-Wl,-G -Wl,-bexpall
export AR=ar -q -X32_64

下面的示例是使用 OBJECT_MODE=64 生成的

我的 GCC 生成选项是

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/freeware/libexec/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/lto-wrapper
Target: powerpc-ibm-aix5.3.0.0
Configured with: ../gcc-4.6.1/configure --with-as=/usr/bin/as --with-ld=/usr/bin/ld --enable-languages=c,c++,fortran --prefix=/opt/freeware --mandir=/opt/freeware/man --infodir=/opt/freeware/info --enable-threads --enable-version-specific-runtime-libs --disable-nls --enable-decimal-float=dpd --host=powerpc-ibm-aix5.3.0.0
Thread model: aix
gcc version 4.6.1 (GCC)
COLLECT_GCC_OPTIONS='-g' '-v' '-Wextra' '-Wall' '-fPIC' '-O2' '-mminimal-toc' '-fpermissive' '-fexceptions' '-Wmissing-field-initializers' '-Wwrite-strings' '-Wformat' '-maix64' '-c' '-I' '.' '-I' '../../../src/HostServices' '-I' '../../../src/InterfaceCTest' '-D' '_LOG' '-D' '_LOGSTDOUT' '-D' '_DEBUG' '-shared-libgcc'
 /opt/freeware/libexec/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/cc1plus -quiet -v -I . -I ../../../src/HostServices -I ../../../src/InterfaceCTest -imultilib ppc64 -D_ALL_SOURCE -D__64BIT__ -D _LOG -D _LOGSTDOUT -D _DEBUG ../../../src/InterfaceCTest/InterfaceCTest.c -quiet -dumpbase InterfaceCTest.c -mminimal-toc -maix64 -auxbase InterfaceCTest -g -O2 -Wextra -Wall -Wmissing-field-initializers -Wwrite-strings -Wformat -version -fPIC -fpermissive -fexceptions -o /u01/ceibo/desen/tmp/ccQYtChL.s

所有模块都链接到共享 gcc(因为它们必须跨共享库抛出异常) :


libConfig.so needs:
         /opt/freeware/lib/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/ppc64/libstdc++.a(libstdc++.so.6)
         /opt/freeware/lib/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/ppc64/libgcc_s.a(shr.o)
         /usr/lib/libc.a(shr_64.o)
         /unix
         /usr/lib/libcrypt.a(shr_64.o)

libHostServices.so needs:
         ../../../bin/aix/debug/libConfig.so
         /opt/freeware/lib/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/ppc64/libstdc++.a(libstdc++.so.6)
         /opt/freeware/lib/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/ppc64/libgcc_s.a(shr.o)
         /usr/lib/libc.a(shr_64.o)
         /unix
         /usr/lib/libcrypt.a(shr_64.o)

InterfaceCTest needs:
         /usr/lib/libc.a(shr_64.o)
         ../../../bin/aix/debug/libHostServices.so
         ../../../bin/aix/debug/libConfig.so
         /opt/freeware/lib/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/ppc64/libgcc_s.a(shr.o)
         /unix
         /usr/lib/libcrypt.a(shr_64.o)
         /opt/freeware/lib/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/ppc64/libstdc++.a(libstdc++.so.6)

当我执行可执行的 InterfaceCTest 时,我得到:


GNU gdb 6.0
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "powerpc-ibm-aix5.1.0.0"...
(gdb) run
...
Program received signal SIGABRT, Aborted.
0x090000000005ca8c in raise () from /usr/lib/libc.a(shr_64.o)
(gdb) where
#0  0x090000000005ca8c in raise () from /usr/lib/libc.a(shr_64.o)
#1  0x0900000000088008 in abort () from /usr/lib/libc.a(shr_64.o)
#2  0x090000000f16a704 in __gnu_cxx::__verbose_terminate_handler() () at  _start_ :95
#3  0x090000000f173b34 in __cxxabiv1::__terminate(void (*)()) (handler=
findvar.c:706: internal-error: value_from_register: Value not stored anywhere!
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) findvar.c:706: internal-error: value_from_register: Value not stored anywhere!
IOT/Abort trap(coredump)
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) 

过去三天我已经通过谷歌搜索了我可能做错的任何事情,但直到现在我什么也没得到。链接 AIX:为什么抛出异常会中止多线程代码?< /a> 对我来说效果很好,所以我确信问题是由于共享库抛出异常造成的。

有谁知道我可能做错了什么?

谢谢,


我做了一个非常简单的测试,现在我很确定这与我的环境有关:

Library libCore.a:

Header Core.h:

#ifdef __cplusplus
extern "C" {
#endif

void ThrowException();

#ifdef __cplusplus
} //extern "C"
#endif

Body:

#include "Core.h"

void ThrowException()
{
    try
    {
    throw new int;
    }
    catch(int * e)
    {
       printf("Exception int caught\n");
    }
    catch(...)
    {
       printf("Exception ... caught\n");
    }   
}

可执行文件CoreCTest

#include "Core.h"

int main()
{

    ThrowException();

    return 1;
}

当我执行可执行文件时,我得到:

./CoreCTest
terminate called after throwing an instance of 'int*'
IOT/Abort trap(coredump)

ldd返回:

CoreCTest needs:
         /usr/lib/libc.a(shr_64.o)
         /usr/lib/libpthreads.a(shr_xpg5_64.o)
         ../../../bin/aix/debug/libCore.a
         /opt/freeware/lib/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/pthread/ppc64/libgcc_s.a(shr.o)
         /unix
         /usr/lib/libcrypt.a(shr_64.o)
         /opt/freeware/lib/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/pthread/ppc64/libstdc++.a(libstdc++.so.6)

有人知道发生了什么吗?任何帮助将非常感激!

谢谢

I'm porting for AIX a pretty stable code wich already runs in Windows, Linux (both 32 and 64 bits) and Solaris SPARC and x86. The code throws exceptions across shared libraries:

Environment: IBM AIX 5.3 64 Bits
Compiler: GCC 4.6.1

Note: The issue occurs either with code compiled in 32 or 64 bits

The architecture is a little bit complicated, but basically we have:
CoreModules.a: Static library which contais all core functions, objects and structures used by the shared libraries. The exception class is defined here and exceptions are thrown by classes defined here. Generated with $(AR).

libConfig.so: Shared library which contains config info. Linked against CoreModules.a. Exceptions are thrown by classes defined here.

libHostServices.so: Shared library which contains the business rules. Linked against CoreModules.a and libConfig.so. Exceptions are thrown by classes defined here.

Here goes my compiling and linking options:

export CXX=g++
export MODE=debug
if [ "$OBJECT_MODE" -eq 64 ]
then 
    export CXXFLAGS="-g -v -W -Wall -fPIC -O2 -mminimal-toc -fpermissive -fexceptions -Wmissing-field-initializers -Wwrite-strings -Wformat -maix64"
else 
    export CXXFLAGS="-g -v -W -Wall -fPIC -O2 -mminimal-toc -fpermissive -fexceptions -Wmissing-field-initializers -Wwrite-strings -Wformat"
export LDFLAGS=-Wl,-G -Wl,-bexpall
export AR=ar -q -X32_64

The examples below were generated with OBJECT_MODE=64

My GCC generation options are

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/freeware/libexec/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/lto-wrapper
Target: powerpc-ibm-aix5.3.0.0
Configured with: ../gcc-4.6.1/configure --with-as=/usr/bin/as --with-ld=/usr/bin/ld --enable-languages=c,c++,fortran --prefix=/opt/freeware --mandir=/opt/freeware/man --infodir=/opt/freeware/info --enable-threads --enable-version-specific-runtime-libs --disable-nls --enable-decimal-float=dpd --host=powerpc-ibm-aix5.3.0.0
Thread model: aix
gcc version 4.6.1 (GCC)
COLLECT_GCC_OPTIONS='-g' '-v' '-Wextra' '-Wall' '-fPIC' '-O2' '-mminimal-toc' '-fpermissive' '-fexceptions' '-Wmissing-field-initializers' '-Wwrite-strings' '-Wformat' '-maix64' '-c' '-I' '.' '-I' '../../../src/HostServices' '-I' '../../../src/InterfaceCTest' '-D' '_LOG' '-D' '_LOGSTDOUT' '-D' '_DEBUG' '-shared-libgcc'
 /opt/freeware/libexec/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/cc1plus -quiet -v -I . -I ../../../src/HostServices -I ../../../src/InterfaceCTest -imultilib ppc64 -D_ALL_SOURCE -D__64BIT__ -D _LOG -D _LOGSTDOUT -D _DEBUG ../../../src/InterfaceCTest/InterfaceCTest.c -quiet -dumpbase InterfaceCTest.c -mminimal-toc -maix64 -auxbase InterfaceCTest -g -O2 -Wextra -Wall -Wmissing-field-initializers -Wwrite-strings -Wformat -version -fPIC -fpermissive -fexceptions -o /u01/ceibo/desen/tmp/ccQYtChL.s

All my modules are linked to shared gcc (as they have to be to throw exception across shared libraries):


libConfig.so needs:
         /opt/freeware/lib/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/ppc64/libstdc++.a(libstdc++.so.6)
         /opt/freeware/lib/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/ppc64/libgcc_s.a(shr.o)
         /usr/lib/libc.a(shr_64.o)
         /unix
         /usr/lib/libcrypt.a(shr_64.o)

libHostServices.so needs:
         ../../../bin/aix/debug/libConfig.so
         /opt/freeware/lib/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/ppc64/libstdc++.a(libstdc++.so.6)
         /opt/freeware/lib/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/ppc64/libgcc_s.a(shr.o)
         /usr/lib/libc.a(shr_64.o)
         /unix
         /usr/lib/libcrypt.a(shr_64.o)

InterfaceCTest needs:
         /usr/lib/libc.a(shr_64.o)
         ../../../bin/aix/debug/libHostServices.so
         ../../../bin/aix/debug/libConfig.so
         /opt/freeware/lib/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/ppc64/libgcc_s.a(shr.o)
         /unix
         /usr/lib/libcrypt.a(shr_64.o)
         /opt/freeware/lib/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/ppc64/libstdc++.a(libstdc++.so.6)

When I execute the executable InterfaceCTest, I get:


GNU gdb 6.0
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "powerpc-ibm-aix5.1.0.0"...
(gdb) run
...
Program received signal SIGABRT, Aborted.
0x090000000005ca8c in raise () from /usr/lib/libc.a(shr_64.o)
(gdb) where
#0  0x090000000005ca8c in raise () from /usr/lib/libc.a(shr_64.o)
#1  0x0900000000088008 in abort () from /usr/lib/libc.a(shr_64.o)
#2  0x090000000f16a704 in __gnu_cxx::__verbose_terminate_handler() () at  _start_ :95
#3  0x090000000f173b34 in __cxxabiv1::__terminate(void (*)()) (handler=
findvar.c:706: internal-error: value_from_register: Value not stored anywhere!
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) findvar.c:706: internal-error: value_from_register: Value not stored anywhere!
IOT/Abort trap(coredump)
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) 

I've passed the last three days googling anything I could be doing wrong but I got nothing untill now. The link AIX: Why does throwing an exception abort multithreaded code? works fine for me, so I'm sure the issue is due to exceptions being thrown across shared libraries.

Does anyone have any idea of what I might be doing wrong?

Thanks


I've done a pretty simple test and now I'm pretty sure It is something related to my environment:

Library libCore.a:

Header Core.h:

#ifdef __cplusplus
extern "C" {
#endif

void ThrowException();

#ifdef __cplusplus
} //extern "C"
#endif

Body:

#include "Core.h"

void ThrowException()
{
    try
    {
    throw new int;
    }
    catch(int * e)
    {
       printf("Exception int caught\n");
    }
    catch(...)
    {
       printf("Exception ... caught\n");
    }   
}

Executable CoreCTest:

#include "Core.h"

int main()
{

    ThrowException();

    return 1;
}

And when I execute my executable, I get:

./CoreCTest
terminate called after throwing an instance of 'int*'
IOT/Abort trap(coredump)

The ldd returns:

CoreCTest needs:
         /usr/lib/libc.a(shr_64.o)
         /usr/lib/libpthreads.a(shr_xpg5_64.o)
         ../../../bin/aix/debug/libCore.a
         /opt/freeware/lib/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/pthread/ppc64/libgcc_s.a(shr.o)
         /unix
         /usr/lib/libcrypt.a(shr_64.o)
         /opt/freeware/lib/gcc/powerpc-ibm-aix5.3.0.0/4.6.1/pthread/ppc64/libstdc++.a(libstdc++.so.6)

Does anyone have ANY idea of what is going on? Any help would be really appreciated!

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我很OK 2024-12-12 03:23:32

我可以通过向链接器提供链接库的“-lsupc++”选项来解决此问题。

I could resolve this issue by supplying the linker with the "-lsupc++" option which links this library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文