在使用ubuntu 13.07和gcc:
的系统上Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v
--with-pkgversion='Ubuntu/Linaro 4.7.3-1ubuntu1'
--with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs
--enable-languages=c,c++,go,fortran,objc,obj-c++
--prefix=/usr --program-suffix=-4.7 --enable-shared
--enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7
--libdir=/usr/lib --enable-nls --with-sysroot=/
--enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--enable-gnu-unique-object --enable-plugin --with-system-zlib
--enable-objc-gc --with-cloog --enable-cloog-backend=ppl
--disable-cloog-version-check --disable-ppl-version-check
--enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-1ubuntu1)
以下代码简单地给出了一个seg-fault:
#include <iostream>
void init()__attribute__((constructor));
int main()
{
return 0;
};
void init()
{
std::cout<<"test";
}
在进入main之前构建时,打算打印 test 。也尝试使用构造函数(65530)并且相同。 我完全不知道出了什么问题。我不希望有这么几行的代码崩溃。另外,我必须提一下,上面的代码曾经用很长时间(3年)的时间用较旧的(我不记得哪个)GCC版本。我犯了一个非常明显的错误吗?
以下是您的类型参考的gdb跟踪。
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b6c131 in std::ostream::sentry::sentry(std::ostream&) ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
(gdb)
(gdb) bt
#0 0x00007ffff7b6c131 in std::ostream::sentry::sentry(std::ostream&) ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#1 0x00007ffff7b6c829 in std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char,
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#2 0x00007ffff7b6cc0f in std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_t
#3 0x000000000040079a in init () at test.cpp:12
#4 0x000000000040084d in __libc_csu_init ()
#5 0x00007ffff7730e35 in __libc_start_main (main=0x40077c <main()>, argc=1,
ubp_av=0x7fffffffd3f8, init=0x4007f0 <__libc_csu_init>,
fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffd3e8)
at libc-start.c:219
#6 0x00000000004006b9 in _start ()