Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Segmentation fault outside of main

I'm working on a large, mixed C++/Fortran project. Currently, the executable segfaults immediately on startup, before reaching main, AFAICT. In fact before loading shared libraries.

Some output:

$ ./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 ?? ()

Also:

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

As can see, it depends on a fair number of libraries but crashes before LD gets to load any of them. I'm not sure where to look next. Any suggestions?

like image 476
Tom Avatar asked Oct 20 '22 22:10

Tom


1 Answers

This was caused by compiling object files with -fPIC and the executable with -shared.

like image 94
Tom Avatar answered Oct 22 '22 12:10

Tom