使用 std::fstream 会导致程序在 PASE for i (7.3) 中以 SIGILL 结束

A. *_*ray 2 c++ fstream g++ ibm-midrange

我正在 IBM 的 CECC 服务的 IBM i 7.3 环境中工作。我正在尝试在 PASE 环境中测试大型应用程序,但在使用该库的脚本时遇到了问题<fstream>。以写入模式打开文件会导致脚本以SIGILL.

为了测试这个问题,我编写了以下脚本:

#include <iostream>
#include <fstream>

int main()
{
        std::ofstream writer;

        std::cout << "Writing file.\n" << std::endl;

        writer.open( "out.txt" );
        if ( !writer.is_open() || !writer.good() )
        {
            std::cerr << "Unable to open file." << std::endl;
            return (1);
        }

        writer << "This is a test.\n" << std::endl;

        writer.close();

        return (0);

}
Run Code Online (Sandbox Code Playgroud)

执行脚本的结果是:

Writing file.

Illegal instruction (core dumped)
Run Code Online (Sandbox Code Playgroud)

在GDB中:

(gdb) run
Starting program: /storage/persist/[app-directory]/test/log/test_write
[New Thread 1]
Writing file.

Program received signal SIGILL, Illegal instruction.
[Switching to Thread 1]
0x08001000a0027940 in _localeinit.bss_3_ () from /QOpenSys/pkgs/bin/../lib/gcc/powerpc-ibm-aix6.1.0.0/6.3.0/../../../libstdc++.so.6(shr_64.o)
(gdb) bt
#0  0x08001000a0027940 in _localeinit.bss_3_ () from /QOpenSys/pkgs/bin/../lib/gcc/powerpc-ibm-aix6.1.0.0/6.3.0/../../../libstdc++.so.6(shr_64.o)
Run Code Online (Sandbox Code Playgroud)

我通过在 CentOS7 开发系统上编译和运行代码来对代码进行快速健全性检查,代码按预期运行并返回,没有错误。我还将代码复制到我的主文件夹中,它在其中out.txt按预期创建和写入,但仍然失败,SIGILL而不是返回且没有错误代码。out.txt(在应用程序的目录中运行也会正确创建 out.txt,但在已使用权限创建时失败-rwx------)。

细节

g++ --version
g++-6.bin (GCC) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.

g++ -dumpmachine
powerpc-ibm-aix6.1.0.0
Run Code Online (Sandbox Code Playgroud)

C++ std 库是通过以下软件包安装的:

libstdcplusplus-devel.ppc64        6.3.0-29                    @ibm             
Run Code Online (Sandbox Code Playgroud)

该代码是使用以下命令编译的:

Writing file.

Illegal instruction (core dumped)
Run Code Online (Sandbox Code Playgroud)

其他不使用的程序<fstream>编译运行没有错误。由于i 平台的 PASE深奥,我很难找到解释此问题潜在原因的文档,但我希望它与编译器设置有关。我想找出原因是什么,以便我可以对代码和/或 makefile 进行适当的更改来解决它。

Kev*_*ler 5

当使用 GCC 编译 PASE 时,您必须使用-pthread而不是-lpthread(或者也设置-D_THREAD_SAFE)。如果没有这个,您可能会遇到问题,因为 PASE 附带的 AIX 头文件具有编译时线程行为。此外,libstdc++ 具有不同的 ABI,具体取决于您-pthread是否在 AIX 平台上进行编译。在 AIX 上,GCC 将自动适当地设置二进制文件的运行时库路径,以加载 pthread 或非 pthread GCC 库,而在 PASE 的开源环境中,我们提供 pthread 版本。