繁体   English   中英

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

[英]Using std::fstream causes program to end with SIGILL in PASE for i (7.3)

我在 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);

}

执行脚本会导致:

Writing file.

Illegal instruction (core dumped)

在 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)

我通过在 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

C++ 标准库与以下 package 一起安装:

libstdcplusplus-devel.ppc64        6.3.0-29                    @ibm             

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

g++ -std=c++17 -Wall -g3 -O0 -fpie test_write.cpp -o test_write -lpthread

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM