【问题标题】:Segmentation fault outside of main主要外部的分段错误
【发布时间】:2015-01-06 10:21:32
【问题描述】:

我正在处理一个大型的混合 C++/Fortran 项目。目前,可执行文件在启动时立即出现段错误,然后到达main,AFAICT。实际上是在加载共享库之前。

一些输出:

$ ./myprog
Segmentation fault (core dumped)
$ gdb ./myprog core
GNU gdb (Ubuntu 7.7-0ubuntu3) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./myprog...done.
[New LWP 9194]
bt
Core was generated by `./myprog'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0000000000000001 in ?? ()
(gdb) bt
#0  0x0000000000000001 in ?? ()
#1  0x00007fff08fa02ca in ?? ()
#2  0x0000000000000000 in ?? ()

还有:

$ LD_DEBUG=all ./myprog
Segmentation fault (core dumped)

$ ldd ./myprog
    linux-vdso.so.1 =>  (0x00007fffd81fe000)
    libxerces-c-3.1.so => /usr/lib/x86_64-linux-gnu/libxerces-c-3.1.so (0x00007f774738e000)
    libxml-security-c.so.17 => /usr/lib/x86_64-linux-gnu/libxml-security-c.so.17 (0x00007f7747083000)
    libblas.so.3 => /usr/lib/libblas.so.3 (0x00007f7746ab6000)
    liblapack.so.3 => /usr/lib/liblapack.so.3 (0x00007f774631a000)
    libboost_serialization.so.1.54.0 => /usr/lib/x86_64-linux-gnu/libboost_serialization.so.1.54.0 (0x00007f77460af000)
    libboost_filesystem.so.1.54.0 => /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.54.0 (0x00007f7745e98000)
    libboost_system.so.1.54.0 => /usr/lib/x86_64-linux-gnu/libboost_system.so.1.54.0 (0x00007f7745c94000)
    libhdf5_cpp.so.7 => /usr/lib/x86_64-linux-gnu/libhdf5_cpp.so.7 (0x00007f7745a43000)
    libhdf5.so.7 => /usr/lib/x86_64-linux-gnu/libhdf5.so.7 (0x00007f77455a6000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7745388000)
    libgfortran.so.3 => /usr/lib/x86_64-linux-gnu/libgfortran.so.3 (0x00007f774506f000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7744e6a000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f7744b5f000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7744859000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7744641000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f774427b000)
    libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f7743ea1000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f7743c87000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f7756ed5000)
    libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007f7743a49000)

正如所见,它依赖于相当数量的库,但在 LD 加载其中任何一个之前就崩溃了。我不知道下一步该往哪里看。有什么建议吗?

【问题讨论】:

    标签: c++ linker segmentation-fault fortran


    【解决方案1】:

    这是由使用-fPIC 编译目标文件和使用-shared 编译可执行文件引起的。

    【讨论】:

    • 如果您仍然需要executable .so,则需要使用-pie 而不是(或至少在之后)-shared
    猜你喜欢
    • 2013-11-13
    • 2016-03-24
    • 1970-01-01
    • 2012-09-04
    • 1970-01-01
    • 2011-06-16
    • 2020-12-22
    • 1970-01-01
    相关资源
    最近更新 更多