[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#812858: g++-5: C++ segfault when cross-compiling for -m32 -static



Package: g++-5
Version: 5.3.1-7
Severity: important

Dear Maintainer,

I cannot compile static binaries of C++ programs for 32bit architectures.

Here is my program:

#include <iostream>
int main(){
  std::cout << "Hello test" << std::endl;
  return 0;
}

I compile like this:
g++-5 -m32 -static -ggdb test.cpp

Then run it:
$ ./a.out
Segmentation fault

I tried debugging it but it crashes before calling main(), somewhere in _init.
Here is my gdb session:

$ gdb
GNU gdb (Debian 7.10-1+b1) 7.10
Copyright (C) 2015 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".
(gdb) file a.out
Reading symbols from a.out...done.
(gdb) b _init
Breakpoint 1 at 0x80481a8
(gdb) r
Starting program: /home/marius/a.out

Breakpoint 1, 0x080481a8 in _init ()
(gdb) s
Single stepping until exit from function _init,
which has no line number information.
0x08048ef0 in __x86.get_pc_thunk.bx ()
(gdb) s
Single stepping until exit from function __x86.get_pc_thunk.bx,
which has no line number information.
0x080481b1 in _init ()
(gdb) s
Single stepping until exit from function _init,
which has no line number information.
0x080e3b6c in __libc_csu_init ()
(gdb) s
Single stepping until exit from function __libc_csu_init,
which has no line number information.
0x08048fb0 in frame_dummy ()
(gdb) s
Single stepping until exit from function frame_dummy,
which has no line number information.
0x080e2fe0 in __register_frame_info_bases ()
(gdb) s
Single stepping until exit from function __register_frame_info_bases,
which has no line number information.

Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()


The problem does not manifest in other configurations:
1) dynamic linking (omitting -static),
2) native x86_64 (omitting -m32)
3) trying equivalanet C program (using stdio.h), even with "-m32 -static"

Therefore I suspect there is something wrong with static linking of C++ library,
but I don't know what __register_frame_info_bases() is.

Please help.

-- System Information:
Debian Release: stretch/sid
  APT prefers testing
  APT policy: (500, 'testing'), (500, 'stable'), (50, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.3.0-1-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_DK.utf8, LC_CTYPE=en_DK.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Init: systemd (via /run/systemd/system)

Versions of packages g++-5 depends on:
ii  gcc-5            5.3.1-7
ii  gcc-5-base       5.3.1-7
ii  libc6            2.21-6
ii  libgmp10         2:6.1.0+dfsg-2
ii  libisl15         0.15-3
ii  libmpc3          1.0.3-1
ii  libmpfr4         3.1.3-2
ii  libstdc++-5-dev  5.3.1-7
ii  zlib1g           1:1.2.8.dfsg-2+b1

g++-5 recommends no packages.

Versions of packages g++-5 suggests:
ii  g++-5-multilib    5.3.1-7
ii  gcc-5-doc         5.2.0-1
pn  libstdc++6-5-dbg  <none>

-- no debconf information


Reply to: