trans object of STL-class on interface which dynamicly load by dlopen - gcc

main.cpp
#include "string"
#include "unordered_map"
#include "iostream"
#include "dlfcn.h"
typedef void x(std::unordered_map<std::string, std::string> &);
int main(int argc, char **argv)
{
auto handle = dlopen("./test3.so", RTLD_NOW);
if(!handle)
{
std::cout << dlerror() << std::endl;
return -1;
}
x *x;
*(void **)&x = dlsym(handle, "x");
// std::unordered_map<std::string, std::string> result{{"y", "Hello, cpp"}}; //ok
std::unordered_map<std::string, std::string> result; //failed if not dynamic link test3.so
x(result);
std::cout << result["x"] << std::endl;
dlclose(handle);
return 0;
}
test3.cpp
#include "unordered_map"
#include "string"
#ifdef __cplusplus
extern "C"
{
#endif
void x(std::unordered_map<std::string, std::string> &result)
{
result["x"] = "Hello, world";
}
#ifdef __cplusplus
}
#endif
if main.cpp build with gcc-11 while test3.cpp with gcc-4.8, the program would crash.
g++ -g -fpic -shared test3.cpp -o test3.so //g++ version is 4.8
g++ -g main.cpp -ldl //g++ version is 11
[zrar#CentOS7 cpp]$ ./a.out
*** Error in `./a.out': munmap_chunk(): invalid pointer: 0x00007ffd3747f020 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x7340f)[0x7f2d328b340f]
/lib64/libc.so.6(+0x78c7e)[0x7f2d328b8c7e]
./test3.so(_ZN9__gnu_cxx13new_allocatorIPNSt8__detail15_Hash_node_baseEE10deallocateEPS3_m+0x20)[0x7f2d3263d506]
./test3.so(_ZNSt10_HashtableISsSt4pairIKSsSsESaIS2_ENSt8__detail10_Select1stESt8equal_toISsESt4hashISsENS4_18_Mod_range_hashingENS4_20_Default_ranged_hashENS4_20_Prime_rehash_policyENS4_17_Hashtable_traitsILb1ELb0ELb1EEEE21_M_deallocate_bucketsEPPNS4_15_Hash_node_baseEm+0x4a)[0x7f2d3263d342]
./test3.so(_ZNSt10_HashtableISsSt4pairIKSsSsESaIS2_ENSt8__detail10_Select1stESt8equal_toISsESt4hashISsENS4_18_Mod_range_hashingENS4_20_Default_ranged_hashENS4_20_Prime_rehash_policyENS4_17_Hashtable_traitsILb1ELb0ELb1EEEE13_M_rehash_auxEmSt17integral_constantIbLb1EE+0x188)[0x7f2d3263d08a]
./test3.so(_ZNSt10_HashtableISsSt4pairIKSsSsESaIS2_ENSt8__detail10_Select1stESt8equal_toISsESt4hashISsENS4_18_Mod_range_hashingENS4_20_Default_ranged_hashENS4_20_Prime_rehash_policyENS4_17_Hashtable_traitsILb1ELb0ELb1EEEE9_M_rehashEmRKm+0x2b)[0x7f2d3263cb4f]
./test3.so(_ZNSt10_HashtableISsSt4pairIKSsSsESaIS2_ENSt8__detail10_Select1stESt8equal_toISsESt4hashISsENS4_18_Mod_range_hashingENS4_20_Default_ranged_hashENS4_20_Prime_rehash_policyENS4_17_Hashtable_traitsILb1ELb0ELb1EEEE21_M_insert_unique_nodeEmmPNS4_10_Hash_nodeIS2_Lb1EEE+0x85)[0x7f2d3263c7eb]
./test3.so(_ZNSt8__detail9_Map_baseISsSt4pairIKSsSsESaIS3_ENS_10_Select1stESt8equal_toISsESt4hashISsENS_18_Mod_range_hashingENS_20_Default_ranged_hashENS_20_Prime_rehash_policyENS_17_Hashtable_traitsILb1ELb0ELb1EEELb1EEixEOSs+0xc2)[0x7f2d3263c3b6]
./test3.so(_ZNSt13unordered_mapISsSsSt4hashISsESt8equal_toISsESaISt4pairIKSsSsEEEixEOSs+0x2e)[0x7f2d3263c2f2]
./test3.so(x+0x43)[0x7f2d3263c138]
./a.out[0x40279a]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7f2d32861ac5]
./a.out[0x402661]
======= Memory map: ========
00400000-00402000 r--p 00000000 fd:00 100685803 /home/zrar/Documents/cpp/a.out
00402000-0040a000 r-xp 00002000 fd:00 100685803 /home/zrar/Documents/cpp/a.out
0040a000-0040f000 r--p 0000a000 fd:00 100685803 /home/zrar/Documents/cpp/a.out
0040f000-00410000 r--p 0000e000 fd:00 100685803 /home/zrar/Documents/cpp/a.out
00410000-00411000 rw-p 0000f000 fd:00 100685803 /home/zrar/Documents/cpp/a.out
00aa2000-00ac3000 rw-p 00000000 00:00 0 [heap]
7f2d32636000-7f2d3263f000 r-xp 00000000 fd:00 100685761 /home/zrar/Documents/cpp/test3.so
7f2d3263f000-7f2d3283e000 ---p 00009000 fd:00 100685761 /home/zrar/Documents/cpp/test3.so
7f2d3283e000-7f2d3283f000 r--p 00008000 fd:00 100685761 /home/zrar/Documents/cpp/test3.so
7f2d3283f000-7f2d32840000 rw-p 00009000 fd:00 100685761 /home/zrar/Documents/cpp/test3.so
7f2d32840000-7f2d329e2000 r-xp 00000000 fd:00 452646 /usr/lib64/libc-2.18.so
7f2d329e2000-7f2d32be2000 ---p 001a2000 fd:00 452646 /usr/lib64/libc-2.18.so
7f2d32be2000-7f2d32be6000 r--p 001a2000 fd:00 452646 /usr/lib64/libc-2.18.so
7f2d32be6000-7f2d32be8000 rw-p 001a6000 fd:00 452646 /usr/lib64/libc-2.18.so
7f2d32be8000-7f2d32bec000 rw-p 00000000 00:00 0
7f2d32bec000-7f2d32c01000 r-xp 00000000 fd:00 1527643 /usr/lib64/libgcc_s-4.8.5-20150702.so.1
7f2d32c01000-7f2d32e00000 ---p 00015000 fd:00 1527643 /usr/lib64/libgcc_s-4.8.5-20150702.so.1
7f2d32e00000-7f2d32e01000 r--p 00014000 fd:00 1527643 /usr/lib64/libgcc_s-4.8.5-20150702.so.1
7f2d32e01000-7f2d32e02000 rw-p 00015000 fd:00 1527643 /usr/lib64/libgcc_s-4.8.5-20150702.so.1
7f2d32e02000-7f2d32f03000 r-xp 00000000 fd:00 1459 /usr/lib64/libm-2.18.so
7f2d32f03000-7f2d33102000 ---p 00101000 fd:00 1459 /usr/lib64/libm-2.18.so
7f2d33102000-7f2d33103000 r--p 00100000 fd:00 1459 /usr/lib64/libm-2.18.so
7f2d33103000-7f2d33104000 rw-p 00101000 fd:00 1459 /usr/lib64/libm-2.18.so
7f2d33104000-7f2d331ed000 r-xp 00000000 fd:00 18326 /usr/lib64/libstdc++.so.6.0.19
7f2d331ed000-7f2d333ed000 ---p 000e9000 fd:00 18326 /usr/lib64/libstdc++.so.6.0.19
7f2d333ed000-7f2d333f5000 r--p 000e9000 fd:00 18326 /usr/lib64/libstdc++.so.6.0.19
7f2d333f5000-7f2d333f7000 rw-p 000f1000 fd:00 18326 /usr/lib64/libstdc++.so.6.0.19
7f2d333f7000-7f2d3340c000 rw-p 00000000 00:00 0
7f2d3340c000-7f2d3340e000 r-xp 00000000 fd:00 452582 /usr/lib64/libdl-2.18.so
7f2d3340e000-7f2d3360e000 ---p 00002000 fd:00 452582 /usr/lib64/libdl-2.18.so
7f2d3360e000-7f2d3360f000 r--p 00002000 fd:00 452582 /usr/lib64/libdl-2.18.so
7f2d3360f000-7f2d33610000 rw-p 00003000 fd:00 452582 /usr/lib64/libdl-2.18.so
7f2d33610000-7f2d33630000 r-xp 00000000 fd:00 230826 /usr/lib64/ld-2.18.so
7f2d33812000-7f2d33818000 rw-p 00000000 00:00 0
7f2d3382e000-7f2d33830000 rw-p 00000000 00:00 0
7f2d33830000-7f2d33831000 r--p 00020000 fd:00 230826 /usr/lib64/ld-2.18.so
7f2d33831000-7f2d33832000 rw-p 00021000 fd:00 230826 /usr/lib64/ld-2.18.so
7f2d33832000-7f2d33833000 rw-p 00000000 00:00 0
7ffd37461000-7ffd37482000 rw-p 00000000 00:00 0 [stack]
7ffd375d0000-7ffd375d2000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Aborted
[zrar#CentOS7 cpp]$ ldd a.out
linux-vdso.so.1 (0x00007ffc793ca000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007ff2ebd37000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007ff2eba2f000)
libm.so.6 => /lib64/libm.so.6 (0x00007ff2eb72d000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007ff2eb517000)
libc.so.6 => /lib64/libc.so.6 (0x00007ff2eb16b000)
/lib64/ld-linux-x86-64.so.2 (0x00007ff2ebf3b000)
[zrar#CentOS7 cpp]$ ldd test3.so
linux-vdso.so.1 (0x00007ffeff7c6000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fb3c0764000)
libm.so.6 => /lib64/libm.so.6 (0x00007fb3c0462000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fb3c024c000)
libc.so.6 => /lib64/libc.so.6 (0x00007fb3bfea0000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb3c0c76000)
if main.cpp build with test3.so in linking list, the program would run normaly.
g++ -g -fpic -shared test3.cpp -o test3.so //g++ version is 4.8
g++ -g main.cpp -Wl,-rpath,'$ORIGIN' -ldl test3.so //g++ version is 11
[zrar#CentOS7 cpp]$ ./a.out
Hello, world
[zrar#CentOS7 cpp]$ ldd ./a.out
linux-vdso.so.1 (0x00007ffea6bb9000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fd670b7f000)
test3.so => /home/zrar/Documents/cpp/test3.so (0x00007fd670975000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fd67066d000)
libm.so.6 => /lib64/libm.so.6 (0x00007fd67036b000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fd670155000)
libc.so.6 => /lib64/libc.so.6 (0x00007fd66fda9000)
/lib64/ld-linux-x86-64.so.2 (0x00007fd670d83000)
[zrar#CentOS7 cpp]$ ldd test3.so
linux-vdso.so.1 (0x00007ffc91596000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fc484378000)
libm.so.6 => /lib64/libm.so.6 (0x00007fc484076000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fc483e60000)
libc.so.6 => /lib64/libc.so.6 (0x00007fc483ab4000)
/lib64/ld-linux-x86-64.so.2 (0x00007fc48488a000)
In my requirment, I want to dynamicly load a plugin(may be built with other-release gcc) and trans STL object directly(host and plugin are both written in cpp, and wrapping of class in c-style is a complexity work) in plugin interface.

I do not have g++-4.8 handy, but chances are that if you compile the following code with g++-4.8 and g++-11, then run nm foo.o | grep Function, you will get different mangled name.
#include <unordered_map>
#include <string>
void Function(std::unordered_map<std::string, std::string>& result) {}
Using g++-11 I get this:
0000000000000000 T _Z8FunctionRSt13unordered_mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_St4hashIS5_ESt8equal_toIS5_ESaISt4pairIKS5_S5_EEE
If the function name is different between the two compilers, then this function is not ABI-compatible, and you can't do what you want.
By marking the function as extern "C" you've hidden this ABI incompatibility from the compiler, but if you lie to the compiler (sooner or later) it will get you.
(If the function name is the same, GCC developers made a mistake.)
wrapping of class in c-style is a complexity work) in plugin interface
Too bad. If the requirement is for different compilers (gcc-4.x and gcc-11.x are different compilers for all practical purposes) then there is no shortcut -- you must ensure ABI compatibility, and the only sure way to achieve that is to only transfer C structs across the interface.

Well, there is certain diffencence between dynamic-link and dynamic-load.
if library is dynamic linked, the library could see symbol in main program
if library is dynamic loaded, the library couldn't see symbol in main program unless the main program is built with option -export-dynamic.
In the former test
a.out dynamic load test3.so, a hash bucket is allocate with main program's function but deallocate with test3.so's function, so a.out will crash.
a.out dynamic load test3.so, hash bucket allocate and deallocate both are define in main program, so a.out is normal

Related

STXXL fails at creating a map of strings in long numeric

With the code that follows, I want to create a map of type std::map. By using a debugger, I got that the exception was raised by stl_pair.h at line 368 (pair& operator=(typename conditional<__and_<is_copy_assignable<_T1>, is_copy_assignable<_T2>>::value, const pair&, const __wrap_nonesuch&>::type __p)), which was invoked by the map scanning of cur (*(cur + 1) = *cur;) in the leaf.h insert function of stxxl. I provide the code I used in the following source code:
#include <stxxl/map>
#include <fstream>
#include <string>
#include <cstdint>
typedef uint_fast64_t LONG_NUMERIC;
std::string random_string( size_t length )
{
auto randchar = []() -> char
{
const char charset[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
const size_t max_index = (sizeof(charset) - 1);
return charset[ rand() % max_index ];
};
std::string str(length,0);
std::generate_n( str.begin(), length, randchar );
return str;
}
struct CompareGreater22
{
bool operator () (const std::string& a, const std::string& b) const
{ return a > b; }
static std::string max_value()
{ return std::string(); }
};
int main(int argc, char** argv) {
stxxl::config * cfg = stxxl::config::get_instance();
stxxl::disk_config disk1("/mnt/DEC4763AC47614CD/stxxl.tmp", 100 * 1024 * 1024, "syscall unlink");
disk1.direct = stxxl::disk_config::DIRECT_ON; // force O_DIRECT
// add disk to config
cfg->add_disk(disk1);
// template parameter <KeyType, DataType, CompareType, RawNodeSize, RawLeafSize, PDAllocStrategy (optional)>
typedef stxxl::map<std::string, LONG_NUMERIC, CompareGreater22, DATA_NODE_BLOCK_SIZE, DATA_LEAF_BLOCK_SIZE> map_type3;
// Constructor map(node_cache_size_in_bytes, leaf_cache_size_in_bytes)
map_type3 t((map_type3::node_block_type::raw_size)*3, (map_type3::leaf_block_type::raw_size)*3);
//vertex_conversion_map_type t{(vertex_conversion_map_type::node_block_type::raw_size)*3, (vertex_conversion_map_type::leaf_block_type::raw_size)*3};
for (LONG_NUMERIC i = 0; i< 2000; i++) {
t.insert(std::make_pair(random_string(10), i));
}
}
I also provide the dump result:
[STXXL-MSG] STXXL v1.4.99 (prerelease/Debug) (git 0a80a8c55993948f7f2f6c2c5a51ff45b403045b) + gnu parallel(20170406)
[STXXL-MSG] Disk '/mnt/DEC4763AC47614CD/stxxl.tmp' is allocated, space: 100 MiB, I/O implementation: syscall direct=on queue=0 devid=0 unlink_on_open
*** Error in `/anon/software/path': free(): invalid pointer: 0x000055c0cd7688d0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7908b)[0x7fd69ff1108b]
/lib/x86_64-linux-gnu/libc.so.6(+0x82c3a)[0x7fd69ff1ac3a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fd69ff1ed2c]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_assignERKS4_+0xaf)[0x7fd6a0ad0fcf]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSERKS4_+0x9)[0x7fd6a0ad1339]
/anon/software/path(+0x19bfb)[0x55c0cc841bfb]
/anon/software/path(+0x15699)[0x55c0cc83d699]
/anon/software/path(+0x10dba)[0x55c0cc838dba]
/anon/software/path(+0xf6fc)[0x55c0cc8376fc]
/anon/software/path(+0xd46d)[0x55c0cc83546d]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1)[0x7fd69feb83f1]
/anon/software/path(+0xd01a)[0x55c0cc83501a]
======= Memory map: ========
55c0cc828000-55c0cc9d8000 r-xp 00000000 08:02 509986 /anon/software/path
55c0ccbd7000-55c0ccbdc000 r--p 001af000 08:02 509986 /anon/software/path
55c0ccbdc000-55c0ccbdd000 rw-p 001b4000 08:02 509986 /anon/software/path
55c0ccbdd000-55c0ccbdf000 rw-p 00000000 00:00 0
55c0cd74a000-55c0cd78c000 rw-p 00000000 00:00 0 [heap]
7fd698000000-7fd698021000 rw-p 00000000 00:00 0
7fd698021000-7fd69c000000 ---p 00000000 00:00 0
7fd69f697000-7fd69f698000 ---p 00000000 00:00 0
7fd69f698000-7fd69fe98000 rw-p 00000000 00:00 0
7fd69fe98000-7fd6a0056000 r-xp 00000000 103:05 795936 /lib/x86_64-linux-gnu/libc-2.24.so
7fd6a0056000-7fd6a0255000 ---p 001be000 103:05 795936 /lib/x86_64-linux-gnu/libc-2.24.so
7fd6a0255000-7fd6a0259000 r--p 001bd000 103:05 795936 /lib/x86_64-linux-gnu/libc-2.24.so
7fd6a0259000-7fd6a025b000 rw-p 001c1000 103:05 795936 /lib/x86_64-linux-gnu/libc-2.24.so
7fd6a025b000-7fd6a025f000 rw-p 00000000 00:00 0
7fd6a025f000-7fd6a0275000 r-xp 00000000 103:05 791133 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fd6a0275000-7fd6a0474000 ---p 00016000 103:05 791133 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fd6a0474000-7fd6a0475000 r--p 00015000 103:05 791133 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fd6a0475000-7fd6a0476000 rw-p 00016000 103:05 791133 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fd6a0476000-7fd6a04a3000 r-xp 00000000 103:05 4335250 /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0
7fd6a04a3000-7fd6a06a2000 ---p 0002d000 103:05 4335250 /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0
7fd6a06a2000-7fd6a06a3000 r--p 0002c000 103:05 4335250 /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0
7fd6a06a3000-7fd6a06a4000 rw-p 0002d000 103:05 4335250 /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0
7fd6a06a4000-7fd6a07ac000 r-xp 00000000 103:05 795940 /lib/x86_64-linux-gnu/libm-2.24.so
7fd6a07ac000-7fd6a09ab000 ---p 00108000 103:05 795940 /lib/x86_64-linux-gnu/libm-2.24.so
7fd6a09ab000-7fd6a09ac000 r--p 00107000 103:05 795940 /lib/x86_64-linux-gnu/libm-2.24.so
7fd6a09ac000-7fd6a09ad000 rw-p 00108000 103:05 795940 /lib/x86_64-linux-gnu/libm-2.24.so
7fd6a09ad000-7fd6a0b26000 r-xp 00000000 103:05 4335931 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22
7fd6a0b26000-7fd6a0d25000 ---p 00179000 103:05 4335931 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22
7fd6a0d25000-7fd6a0d2f000 r--p 00178000 103:05 4335931 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22
7fd6a0d2f000-7fd6a0d31000 rw-p 00182000 103:05 4335931 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22
7fd6a0d31000-7fd6a0d35000 rw-p 00000000 00:00 0
7fd6a0d35000-7fd6a0d4d000 r-xp 00000000 103:05 795951 /lib/x86_64-linux-gnu/libpthread-2.24.so
7fd6a0d4d000-7fd6a0f4d000 ---p 00018000 103:05 795951 /lib/x86_64-linux-gnu/libpthread-2.24.so
7fd6a0f4d000-7fd6a0f4e000 r--p 00018000 103:05 795951 /lib/x86_64-linux-gnu/libpthread-2.24.so
7fd6a0f4e000-7fd6a0f4f000 rw-p 00019000 103:05 795951 /lib/x86_64-linux-gnu/libpthread-2.24.so
7fd6a0f4f000-7fd6a0f53000 rw-p 00000000 00:00 0
7fd6a0f53000-7fd6a0f79000 r-xp 00000000 103:05 795932 /lib/x86_64-linux-gnu/ld-2.24.so
7fd6a114b000-7fd6a1150000 rw-p 00000000 00:00 0
7fd6a1174000-7fd6a1178000 rw-p 00000000 00:00 0
7fd6a1178000-7fd6a1179000 r--p 00025000 103:05 795932 /lib/x86_64-linux-gnu/ld-2.24.so
7fd6a1179000-7fd6a117a000 rw-p 00026000 103:05 795932 /lib/x86_64-linux-gnu/ld-2.24.so
7fd6a117a000-7fd6a117b000 rw-p 00000000 00:00 0
7fff9e622000-7fff9e643000 rw-p 00000000 00:00 0 [stack]
7fff9e714000-7fff9e716000 r--p 00000000 00:00 0 [vvar]
7fff9e716000-7fff9e718000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
TL;DR: Your KeyType is a std::string and consequently non-pod. The STXXL does not support this.
See section Parameterizing STXXL Containers in the official STXXL FAQ.
See How to use std::string as key in stxxl::map here, where somebody had the same issue. Answers below that question describe possible workarounds.

Redirection of crash output

I've found that some programs print Memory Maps and other diagnostic information to the terminal when they crash, even when I redirect file descriptors 1 and 2 (standard out and error, respectively) to files. How can I redirect the diagnostics to a file?
For example, this c++ program:
#include <iostream>
#include <assert.h>
#include <string>
int main(){
using namespace std;
cout<<"foo"<<endl;
cerr<<"bar"<<endl;
string s;
s = "asdf";
delete &s;
}
After compilation, it can be run, redirecting "all" output (g++ foo.cpp && ./a.out > /dev/null 2>&1) but still print the following to the terminal:
======*** Error in `./a.out': double free or corruption (out): 0x00007ffe389313d0 ***
======= Backtrace: =========
/usr/lib/libc.so.6(+0x722ab)[0x7fc7c053f2ab]
/usr/lib/libc.so.6(+0x7890e)[0x7fc7c054590e]
/usr/lib/libc.so.6(+0x7911e)[0x7fc7c054611e]
./a.out[0x400b41]
/usr/lib/libc.so.6(__libc_start_main+0xf1)[0x7fc7c04ed511]
./a.out[0x4009fa]
= Memory map: ========
00400000-00401000 r-xp 00000000 00:27 531373 /tmp/a.out
00601000-00602000 r--p 00001000 00:27 531373 /tmp/a.out
00602000-00603000 rw-p 00002000 00:27 531373 /tmp/a.out
01f1d000-01f4f000 rw-p 00000000 00:00 0 [heap]
7fc7bc000000-7fc7bc021000 rw-p 00000000 00:00 0
7fc7bc021000-7fc7c0000000 ---p 00000000 00:00 0
7fc7c04cd000-7fc7c0668000 r-xp 00000000 08:09 142916 /usr/lib/libc-2.25.so
7fc7c0668000-7fc7c0867000 ---p 0019b000 08:09 142916 /usr/lib/libc-2.25.so
7fc7c0867000-7fc7c086b000 r--p 0019a000 08:09 142916 /usr/lib/libc-2.25.so
7fc7c086b000-7fc7c086d000 rw-p 0019e000 08:09 142916 /usr/lib/libc-2.25.so
7fc7c086d000-7fc7c0871000 rw-p 00000000 00:00 0
7fc7c0871000-7fc7c0887000 r-xp 00000000 08:09 144514 /usr/lib/libgcc_s.so.1
7fc7c0887000-7fc7c0a86000 ---p 00016000 08:09 144514 /usr/lib/libgcc_s.so.1
7fc7c0a86000-7fc7c0a87000 r--p 00015000 08:09 144514 /usr/lib/libgcc_s.so.1
7fc7c0a87000-7fc7c0a88000 rw-p 00016000 08:09 144514 /usr/lib/libgcc_s.so.1
7fc7c0a88000-7fc7c0b9a000 r-xp 00000000 08:09 131998 /usr/lib/libm-2.25.so
7fc7c0b9a000-7fc7c0d99000 ---p 00112000 08:09 131998 /usr/lib/libm-2.25.so
7fc7c0d99000-7fc7c0d9a000 r--p 00111000 08:09 131998 /usr/lib/libm-2.25.so
7fc7c0d9a000-7fc7c0d9b000 rw-p 00112000 08:09 131998 /usr/lib/libm-2.25.so
7fc7c0d9b000-7fc7c0f13000 r-xp 00000000 08:09 141919 /usr/lib/libstdc++.so.6.0.22
7fc7c0f13000-7fc7c1113000 ---p 00178000 08:09 141919 /usr/lib/libstdc++.so.6.0.22
7fc7c1113000-7fc7c111d000 r--p 00178000 08:09 141919 /usr/lib/libstdc++.so.6.0.22
7fc7c111d000-7fc7c111f000 rw-p 00182000 08:09 141919 /usr/lib/libstdc++.so.6.0.22
7fc7c111f000-7fc7c1123000 rw-p 00000000 00:00 0
7fc7c1123000-7fc7c1146000 r-xp 00000000 08:09 142957 /usr/lib/ld-2.25.so
7fc7c1318000-7fc7c131e000 rw-p 00000000 00:00 0
7fc7c1344000-7fc7c1345000 rw-p 00000000 00:00 0
7fc7c1345000-7fc7c1346000 r--p 00022000 08:09 142957 /usr/lib/ld-2.25.so
7fc7c1346000-7fc7c1347000 rw-p 00023000 08:09 142957 /usr/lib/ld-2.25.so
7fc7c1347000-7fc7c1348000 rw-p 00000000 00:00 0
7ffe38911000-7ffe38932000 rw-p 00000000 00:00 0 [stack]
7ffe38945000-7ffe38947000 r--p 00000000 00:00 0 [vvar]
7ffe38947000-7ffe38949000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Aborted (core dumped)
To redirrect output from /dev/tty to a file you can do:
script -q -c 'g++ foo.cpp && ./a.out' /dev/null > /tmp/bla.txt
Taken from here - How to redirect a program that writes to tty?

stack smash error occured in using a staic library

i developed a static library, and a test application to call its
functions.
Now, when i am executing the test application, it was able to get in to
the function and calculate the required values, but when the return is
called it is giving stack smash error
./test_app
USB Handle opened SUCCESSFULLY
*** stack smashing detected ***: /home/avinay/Documents/iProbe/Experiments/iProbe_linux_lib/test_app terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x37)[0x7ffff7b25807]
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x0)[0x7ffff7b257d0]
/home/avinay/Documents/iProbe/Experiments/iProbe_linux_lib/test_app[0x4008ec]
/home/avinay/Documents/iProbe/Experiments/iProbe_linux_lib/test_app[0x4006ed]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7ffff7a3c76d]
/home/avinay/Documents/iProbe/Experiments/iProbe_linux_lib/test_app[0x400619]
======= Memory map: ========
00400000-00402000 r-xp 00000000 08:08 1186 /home/avinay/Documents/iProbe/Experiments/iProbe_linux_lib/test_app
00601000-00602000 r--p 00001000 08:08 1186 /home/avinay/Documents/iProbe/Experiments/iProbe_linux_lib/test_app
00602000-00603000 rw-p 00002000 08:08 1186 /home/avinay/Documents/iProbe/Experiments/iProbe_linux_lib/test_app
00603000-00624000 rw-p 00000000 00:00 0 [heap]
7ffff7805000-7ffff781a000 r-xp 00000000 08:05 658720 /lib/x86_64-linux-gnu/libgcc_s.so.1
7ffff781a000-7ffff7a19000 ---p 00015000 08:05 658720 /lib/x86_64-linux-gnu/libgcc_s.so.1
7ffff7a19000-7ffff7a1a000 r--p 00014000 08:05 658720 /lib/x86_64-linux-gnu/libgcc_s.so.1
7ffff7a1a000-7ffff7a1b000 rw-p 00015000 08:05 658720 /lib/x86_64-linux-gnu/libgcc_s.so.1
7ffff7a1b000-7ffff7bd0000 r-xp 00000000 08:05 658699 /lib/x86_64-linux-gnu/libc-2.15.so
7ffff7bd0000-7ffff7dcf000 ---p 001b5000 08:05 658699 /lib/x86_64-linux-gnu/libc-2.15.so
7ffff7dcf000-7ffff7dd3000 r--p 001b4000 08:05 658699 /lib/x86_64-linux-gnu/libc-2.15.so
7ffff7dd3000-7ffff7dd5000 rw-p 001b8000 08:05 658699 /lib/x86_64-linux-gnu/libc-2.15.so
7ffff7dd5000-7ffff7dda000 rw-p 00000000 00:00 0
7ffff7dda000-7ffff7dfc000 r-xp 00000000 08:05 658679 /lib/x86_64-linux-gnu/ld-2.15.so
7ffff7fdd000-7ffff7fe0000 rw-p 00000000 00:00 0
7ffff7ff6000-7ffff7ffb000 rw-p 00000000 00:00 0
7ffff7ffb000-7ffff7ffc000 r-xp 00000000 00:00 0 [vdso]
7ffff7ffc000-7ffff7ffd000 r--p 00022000 08:05 658679 /lib/x86_64-linux-gnu/ld-2.15.so
7ffff7ffd000-7ffff7fff000 rw-p 00023000 08:05 658679 /lib/x86_64-linux-gnu/ld-2.15.so
7ffffffde000-7ffffffff000 rw-p 00000000 00:00 0 [stack]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Here is the test application
#include <stdio.h>
#include "leapfrog.h"
void main()
{
unsigned int mid=0x0;
USB_Init();
mid = Read_MID();
printf("\n mid = 0x%x\n",mid);
USB_Deinit();
return;
}
The above was the test application and it was referencing this function in the library
uint16 Read_MID(void)
{
int8 buf[8]={0};
uint16 mid;
//Read Vendor id
buf[0] = 0xFE;
msp_write(0x41,buf,1);
msp_read(0x41,buf,2);
mid = buf[0];
mid <<= 8;
mid |= buf[1];
return mid;
}
till the "mid" calculation i could get the correct values. it is reaching till the end while debugging with insight debugger. just after "}" in the console i see the stack smash error.
what might be the cause of the stack smash.
Thank you for time and patience.
I resolved it by adding more array space.
int8 buf[8]={0};
i made it as
int8 buf[10]={0};

Build gcc-4.0.4 on Ubuntu 10.10 32bit. buffer overflow detected

When i build gcc-4.0.4 (on Ubuntu 10.10), there is a problem:
arm-linux-ar rc ./libgcc.a libgcc/./_udivsi3.o libgcc/./_divsi3.o
libgcc/./_umodsi3.o libgcc/./_modsi3.o libgcc/./_dvmd_lnx.o
libgcc/./_muldi3.o libgcc/./_negdi2.o libgcc/./_lshrdi3.o
libgcc/./_ashldi3.o libgcc/./_ashrdi3.o libgcc/./_cmpdi2.o
libgcc/./_ucmpdi2.o libgcc/./_floatdidf.o libgcc/./_floatdisf.o
libgcc/./_fixunsdfsi.o libgcc/./_fixunssfsi.o libgcc/./_fixunsdfdi.o
libgcc/./_fixdfdi.o libgcc/./_fixunssfdi.o libgcc/./_fixsfdi.o
libgcc/./_fixxfdi.o libgcc/./_fixunsxfdi.o libgcc/./_floatdixf.o
libgcc/./_fixunsxfsi.o libgcc/./_fixtfdi.o libgcc/./_fixunstfdi.o
libgcc/./_floatditf.o libgcc/./_clear_cache.o
libgcc/./_enable_execute_stack.o libgcc/./trampoline.o
libgcc/./_main.o libgcc/./_absvsi2.o libgcc/./_absvdi2.o
libgcc/./_addvsi3.o libgcc/./_addvdi3.o libgcc/./_subvsi3.o
libgcc/./_subvdi3.o libgcc/./_mulvsi3.o libgcc/./_mulvdi3.o
libgcc/./_negvsi2.o libgcc/./_negvdi2.o libgcc/./_ctors.o
libgcc/./_ffssi2.o libgcc/./_ffsdi2.o libgcc/./_clz.o
libgcc/./_clzsi2.o libgcc/./_clzdi2.o libgcc/./_ctzsi2.o
libgcc/./_ctzdi2.o libgcc/./_popcount_tab.o libgcc/./_popcountsi2.o
libgcc/./_popcountdi2.o libgcc/./_paritysi2.o libgcc/./_paritydi2.o
libgcc/./_powisf2.o libgcc/./_powidf2.o libgcc/./_powixf2.o
libgcc/./_powitf2.o libgcc/./_mulsc3.o libgcc/./_muldc3.o
libgcc/./_mulxc3.o libgcc/./_multc3.o libgcc/./_divsc3.o
libgcc/./_divdc3.o libgcc/./_divxc3.o libgcc/./_divtc3.o
libgcc/./eprintf.o libgcc/./_gcc_bcmp.o libgcc/./_divdi3.o
libgcc/./_moddi3.o libgcc/./_udivdi3.o libgcc/./_umoddi3.o
libgcc/./_udiv_w_sdiv.o libgcc/./_udivmoddi4.o libgcc/./unwind-dw2.o
libgcc/./unwind-dw2-fde-glibc.o libgcc/./unwind-sjlj.o
libgcc/./gthr-gnat.o libgcc/./unwind-c.o
* buffer overflow detected *: arm-linux-ar terminated
======= Backtrace: ========= /lib/libc.so.6(__fortify_fail+0x50)[0x8f1890]
/lib/libc.so.6(+0xe478a)[0x8f078a] /lib/libc.so.6(+0xe3ec8)[0x8efec8]
/lib/libc.so.6(_IO_default_xsputn+0x9e)[0x8765ee]
/lib/libc.so.6(_IO_padn+0xd8)[0x869f78]
/lib/libc.so.6(_IO_vfprintf+0x2b79)[0x84bd89]
/lib/libc.so.6(__vsprintf_chk+0xad)[0x8eff7d]
/lib/libc.so.6(__sprintf_chk+0x2d)[0x8efebd] arm-linux-ar[0x8050c05]
arm-linux-ar[0x804ed7e] arm-linux-ar[0x805168c]
arm-linux-ar[0x8055178] arm-linux-ar[0x804b7d2]
arm-linux-ar[0x804c494]
/lib/libc.so.6(__libc_start_main+0xe7)[0x822ce7]
arm-linux-ar[0x80496e1]
======= Memory map: ======== 003e4000-00400000 r-xp 00000000 08:01 131636 /lib/ld-2.12.1.so 00400000-00401000 r--p 0001b000 08:01
131636 /lib/ld-2.12.1.so 00401000-00402000 rw-p 0001c000 08:01
131636 /lib/ld-2.12.1.so 006b2000-006cc000 r-xp 00000000 08:01
131244 /lib/libgcc_s.so.1 006cc000-006cd000 r--p 00019000 08:01
131244 /lib/libgcc_s.so.1 006cd000-006ce000 rw-p 0001a000 08:01
131244 /lib/libgcc_s.so.1 0080c000-00963000 r-xp 00000000 08:01
132225 /lib/libc-2.12.1.so 00963000-00965000 r--p 00157000 08:01
132225 /lib/libc-2.12.1.so 00965000-00966000 rw-p 00159000 08:01
132225 /lib/libc-2.12.1.so 00966000-00969000 rw-p 00000000 00:00 0
00a42000-00a43000 r-xp 00000000 00:00 0 [vdso]
08048000-08097000 r-xp 00000000 08:01 427851
/home/zouhansi/armlinux/tools/bin/arm-linux-ar 08097000-08098000 r--p
0004e000 08:01 427851
/home/zouhansi/armlinux/tools/bin/arm-linux-ar 08098000-08099000 rw-p
0004f000 08:01 427851
/home/zouhansi/armlinux/tools/bin/arm-linux-ar 08099000-0809d000 rw-p
00000000 00:00 0 09354000-09558000 rw-p 00000000 00:00 0
[heap] b74c1000-b74c8000 r--s 00000000 08:01 661517
/usr/lib/gconv/gconv-modules.cache b74c8000-b765b000 r--p 002a3000
08:01 657761 /usr/lib/locale/locale-archive b765b000-b785b000 r--p
00000000 08:01 657761 /usr/lib/locale/locale-archive
b785b000-b785c000 rw-p 00000000 00:00 0 b785f000-b786b000 rw-p
00000000 00:00 0 bf839000-bf85c000 rw-p 00000000 00:00 0
[stack]
I find some solution from network to add "-D_FORTIFY_SOURCE=0" in
CFLAGS. I had edit Makefile like this: CFLAGS_FOR_BUILD = -g -O2
-D_FORTIFY_SOURCE=0
I make it again. But this problem is occured again.
Could you give some comments? Thanks a lot.
I had a similar problem building a GCC cross-compiler - it seems binutils is full of unsafe calls to sprintf().
A workaround which worked for me was to set:
export CFLAGS="-fno-stack-protector -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0"
These have to be set before running ../src/configure.
There seems to be a binutils patch here: http://www.redhat.com/archives/fedora-extras-commits/2009-November/msg06284.html but it didn't apply cleanly to the source I was using, so I stuck with CFLAGS hack.
After I cross-compiled GCC with the latest version of binutils, it worked and I didn't get the buffer overflow anymore.
This was the line I used, after I installed the latest binutils:
../gcc-4.5.1/configure --target=arm-linux --prefix=/.../toolchain/bin/binutils --disable-nls --disable-multilib --disable-shared --disable-decimal-float --disable--threads --disable-libmudflap --disable-libssp --disable-libgomp --enable-languages=c --with-system-zlib --with-newlib

Debugging a Ruby segfault

How do I determine if a segfault is due to inconsistent libraries, or a bug in some gem I'm using?
$ uname -a
Linux [redacted] 3.2.0-24-generic #39-Ubuntu SMP Mon May 21 16:52:17 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
$ ruby1.9.1 --version
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
$ CPUPROFILE_OBJECTS=1 CPUPROFILE=/tmp/my_app_profile_objects RUBYOPT="-r`gem1.9.1 which perftools | tail -1`" ruby1.9.1 -e '[].map'
-e:1: [BUG] Segmentation fault
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0004 p:---- s:0009 b:0009 l:000008 d:000008 CFUNC :map
c:0003 p:0010 s:0006 b:0006 l:0011f8 d:0002f8 EVAL -e:1
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:0011f8 d:0011f8 TOP
-- Ruby level backtrace information ----------------------------------------
-e:1:in `<main>'
-e:1:in `map'
-- C level backtrace information -------------------------------------------
/usr/lib/libruby-1.9.1.so.1.9(+0x155b29) [0x7fd39f1dab29] ../sysdeps/x86_64/multiarch/strcpy-ssse3.S:1638
/usr/lib/libruby-1.9.1.so.1.9(+0x57709) [0x7fd39f0dc709] vfscanf.c:1777
/usr/lib/libruby-1.9.1.so.1.9(rb_bug+0xb7) [0x7fd39f0dd137] vfscanf.c:1796
/usr/lib/libruby-1.9.1.so.1.9(+0xf604f) [0x7fd39f17b04f] wcfuncs.c:49
/lib/x86_64-linux-gnu/libc.so.6(+0x364c0) [0x7fd39ecfe4c0] ../sysdeps/posix/killpg.c:38
/usr/lib/libruby-1.9.1.so.1.9(rb_check_type+0xd8) [0x7fd39f0de7e8] vfscanf.c:1963
/usr/lib/libruby-1.9.1.so.1.9(rb_data_typed_object_alloc+0xad) [0x7fd39f0f340d] iofdopen.c:51
/usr/lib/libruby-1.9.1.so.1.9(+0x54f9f) [0x7fd39f0d9f9f] vfscanf.c:2014
/usr/lib/libruby-1.9.1.so.1.9(rb_enumeratorize+0x33) [0x7fd39f0dae33] vfscanf.c:2373
/usr/lib/libruby-1.9.1.so.1.9(+0x14e9a1) [0x7fd39f1d39a1] ../sysdeps/x86_64/multiarch/../strcmp.S:293
/usr/lib/libruby-1.9.1.so.1.9(+0x145912) [0x7fd39f1ca912] ../sysdeps/x86_64/multiarch/memcpy-ssse3.S:2001
/usr/lib/libruby-1.9.1.so.1.9(+0x14b31d) [0x7fd39f1d031d] ../sysdeps/x86_64/multiarch/memcpy-ssse3-back.S:2032
/usr/lib/libruby-1.9.1.so.1.9(rb_iseq_eval_main+0xaf) [0x7fd39f1d769f] ../sysdeps/x86_64/multiarch/../strcmp.S:1811
/usr/lib/libruby-1.9.1.so.1.9(+0x5b172) [0x7fd39f0e0172] vfscanf.c:1471
/usr/lib/libruby-1.9.1.so.1.9(ruby_exec_node+0x1d) [0x7fd39f0e0c5d] vfscanf.c:2288
/usr/lib/libruby-1.9.1.so.1.9(ruby_run_node+0x1e) [0x7fd39f0e280e] psiginfo.c:209
ruby1.9.1() [0x4007db]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed) [0x7fd39ece976d] libc-start.c:226
ruby1.9.1() [0x400809]
-- Other runtime information -----------------------------------------------
* Loaded script: -e
* Loaded features:
0 enumerator.so
1 /usr/lib/ruby/1.9.1/x86_64-linux/enc/encdb.so
2 /usr/lib/ruby/1.9.1/x86_64-linux/enc/trans/transdb.so
3 /usr/lib/ruby/1.9.1/rubygems/defaults.rb
4 /usr/lib/ruby/1.9.1/x86_64-linux/rbconfig.rb
5 /usr/lib/ruby/1.9.1/rubygems/deprecate.rb
6 /usr/lib/ruby/1.9.1/rubygems/exceptions.rb
7 /usr/lib/ruby/1.9.1/rubygems/custom_require.rb
8 /usr/lib/ruby/1.9.1/rubygems.rb
9 /var/lib/gems/1.9.1/gems/perftools.rb-2.0.0/lib/perftools.so
* Process memory map:
00400000-00401000 r-xp 00000000 08:07 704429 /usr/bin/ruby1.9.1
00600000-00601000 r--p 00000000 08:07 704429 /usr/bin/ruby1.9.1
00601000-00602000 rw-p 00001000 08:07 704429 /usr/bin/ruby1.9.1
01464000-016e4000 rw-p 00000000 00:00 0 [heap]
7fd39c3e1000-7fd39cf53000 rw-p 00000000 00:00 0
7fd39cf53000-7fd39cf68000 r-xp 00000000 08:06 5443 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fd39cf68000-7fd39d167000 ---p 00015000 08:06 5443 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fd39d167000-7fd39d168000 r--p 00014000 08:06 5443 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fd39d168000-7fd39d169000 rw-p 00015000 08:06 5443 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fd39d169000-7fd39d24b000 r-xp 00000000 08:07 137087 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
7fd39d24b000-7fd39d44a000 ---p 000e2000 08:07 137087 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
7fd39d44a000-7fd39d452000 r--p 000e1000 08:07 137087 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
7fd39d452000-7fd39d454000 rw-p 000e9000 08:07 137087 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
7fd39d454000-7fd39d469000 rw-p 00000000 00:00 0
7fd39d469000-7fd39d47d000 r-xp 00000000 08:06 144897 /var/lib/gems/1.9.1/gems/perftools.rb-2.0.0/lib/perftools.so
7fd39d47d000-7fd39d67c000 ---p 00014000 08:06 144897 /var/lib/gems/1.9.1/gems/perftools.rb-2.0.0/lib/perftools.so
7fd39d67c000-7fd39d67d000 r--p 00013000 08:06 144897 /var/lib/gems/1.9.1/gems/perftools.rb-2.0.0/lib/perftools.so
7fd39d67d000-7fd39d67e000 rw-p 00014000 08:06 144897 /var/lib/gems/1.9.1/gems/perftools.rb-2.0.0/lib/perftools.so
7fd39d67e000-7fd39d682000 rw-p 00000000 00:00 0
7fd39d682000-7fd39d684000 r-xp 00000000 08:07 157727 /usr/lib/ruby/1.9.1/x86_64-linux/enc/trans/transdb.so
7fd39d684000-7fd39d884000 ---p 00002000 08:07 157727 /usr/lib/ruby/1.9.1/x86_64-linux/enc/trans/transdb.so
7fd39d884000-7fd39d885000 r--p 00002000 08:07 157727 /usr/lib/ruby/1.9.1/x86_64-linux/enc/trans/transdb.so
7fd39d885000-7fd39d886000 rw-p 00003000 08:07 157727 /usr/lib/ruby/1.9.1/x86_64-linux/enc/trans/transdb.so
7fd39d886000-7fd39d888000 r-xp 00000000 08:07 157743 /usr/lib/ruby/1.9.1/x86_64-linux/enc/encdb.so
7fd39d888000-7fd39da87000 ---p 00002000 08:07 157743 /usr/lib/ruby/1.9.1/x86_64-linux/enc/encdb.so
7fd39da87000-7fd39da88000 r--p 00001000 08:07 157743 /usr/lib/ruby/1.9.1/x86_64-linux/enc/encdb.so
7fd39da88000-7fd39da89000 rw-p 00002000 08:07 157743 /usr/lib/ruby/1.9.1/x86_64-linux/enc/encdb.so
7fd39da89000-7fd39e16c000 r--p 00000000 08:07 134744 /usr/lib/locale/locale-archive
7fd39e16c000-7fd39e265000 r-xp 00000000 08:06 5454 /lib/x86_64-linux-gnu/libm-2.15.so
7fd39e265000-7fd39e464000 ---p 000f9000 08:06 5454 /lib/x86_64-linux-gnu/libm-2.15.so
7fd39e464000-7fd39e465000 r--p 000f8000 08:06 5454 /lib/x86_64-linux-gnu/libm-2.15.so
7fd39e465000-7fd39e466000 rw-p 000f9000 08:06 5454 /lib/x86_64-linux-gnu/libm-2.15.so
7fd39e466000-7fd39e46f000 r-xp 00000000 08:06 5430 /lib/x86_64-linux-gnu/libcrypt-2.15.so
7fd39e46f000-7fd39e66f000 ---p 00009000 08:06 5430 /lib/x86_64-linux-gnu/libcrypt-2.15.so
7fd39e66f000-7fd39e670000 r--p 00009000 08:06 5430 /lib/x86_64-linux-gnu/libcrypt-2.15.so
7fd39e670000-7fd39e671000 rw-p 0000a000 08:06 5430 /lib/x86_64-linux-gnu/libcrypt-2.15.so
7fd39e671000-7fd39e69f000 rw-p 00000000 00:00 0
7fd39e69f000-7fd39e6a1000 r-xp 00000000 08:06 5435 /lib/x86_64-linux-gnu/libdl-2.15.so
7fd39e6a1000-7fd39e8a1000 ---p 00002000 08:06 5435 /lib/x86_64-linux-gnu/libdl-2.15.so
7fd39e8a1000-7fd39e8a2000 r--p 00002000 08:06 5435 /lib/x86_64-linux-gnu/libdl-2.15.so
7fd39e8a2000-7fd39e8a3000 rw-p 00003000 08:06 5435 /lib/x86_64-linux-gnu/libdl-2.15.so
7fd39e8a3000-7fd39e8aa000 r-xp 00000000 08:06 5508 /lib/x86_64-linux-gnu/librt-2.15.so
7fd39e8aa000-7fd39eaa9000 ---p 00007000 08:06 5508 /lib/x86_64-linux-gnu/librt-2.15.so
7fd39eaa9000-7fd39eaaa000 r--p 00006000 08:06 5508 /lib/x86_64-linux-gnu/librt-2.15.so
7fd39eaaa000-7fd39eaab000 rw-p 00007000 08:06 5508 /lib/x86_64-linux-gnu/librt-2.15.so
7fd39eaab000-7fd39eac3000 r-xp 00000000 08:06 5502 /lib/x86_64-linux-gnu/libpthread-2.15.so
7fd39eac3000-7fd39ecc2000 ---p 00018000 08:06 5502 /lib/x86_64-linux-gnu/libpthread-2.15.so
7fd39ecc2000-7fd39ecc3000 r--p 00017000 08:06 5502 /lib/x86_64-linux-gnu/libpthread-2.15.so
7fd39ecc3000-7fd39ecc4000 rw-p 00018000 08:06 5502 /lib/x86_64-linux-gnu/libpthread-2.15.so
7fd39ecc4000-7fd39ecc8000 rw-p 00000000 00:00 0
7fd39ecc8000-7fd39ee7b000 r-xp 00000000 08:06 5422 /lib/x86_64-linux-gnu/libc-2.15.so
7fd39ee7b000-7fd39f07a000 ---p 001b3000 08:06 5422 /lib/x86_64-linux-gnu/libc-2.15.so
7fd39f07a000-7fd39f07e000 r--p 001b2000 08:06 5422 /lib/x86_64-linux-gnu/libc-2.15.so
7fd39f07e000-7fd39f080000 rw-p 001b6000 08:06 5422 /lib/x86_64-linux-gnu/libc-2.15.so
7fd39f080000-7fd39f085000 rw-p 00000000 00:00 0
7fd39f085000-7fd39f0f0000 r-xp 00000000 08:07 158047 /usr/lib/libruby-1.9.1.so.1.9.1
7fd39f0f0000-7fd39f0f3000 rwxp 0006b000 08:07 158047 /usr/lib/libruby-1.9.1.so.1.9.1
7fd39f0f3000-7fd39f275000 r-xp 0006e000 08:07 158047 /usr/lib/libruby-1.9.1.so.1.9.1
7fd39f275000-7fd39f474000 ---p 001f0000 08:07 158047 /usr/lib/libruby-1.9.1.so.1.9.1
7fd39f474000-7fd39f479000 r--p 001ef000 08:07 158047 /usr/lib/libruby-1.9.1.so.1.9.1
7fd39f479000-7fd39f47d000 rw-p 001f4000 08:07 158047 /usr/lib/libruby-1.9.1.so.1.9.1
7fd39f47d000-7fd39f499000 rw-p 00000000 00:00 0
7fd39f499000-7fd39f4bb000 r-xp 00000000 08:06 5402 /lib/x86_64-linux-gnu/ld-2.15.so
7fd39f59b000-7fd39f6a1000 rw-p 00000000 00:00 0
7fd39f6b4000-7fd39f6b5000 rw-p 00000000 00:00 0
7fd39f6b5000-7fd39f6b6000 ---p 00000000 00:00 0
7fd39f6b6000-7fd39f6bb000 rw-p 00000000 00:00 0
7fd39f6bb000-7fd39f6bc000 r--p 00022000 08:06 5402 /lib/x86_64-linux-gnu/ld-2.15.so
7fd39f6bc000-7fd39f6be000 rw-p 00023000 08:06 5402 /lib/x86_64-linux-gnu/ld-2.15.so
7fff507f8000-7fff50819000 rw-p 00000000 00:00 0 [stack]
7fff50941000-7fff50942000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html
Aborted (core dumped)
You can find out which part of the software caused a segmentation fault by - and this is probably not a surprise to you - debugging!. As you can see...
Aborted (core dumped)
...there is a core dump.
Just fire up gdb on your executable and the core dump and find out what the parameters to that strcpy (see the first line of your backtrace) were. Then walk backwards trough the stack traces and the code. It seems like debugging symbols have been compiled in, so you are lucky and you can see which function is actually called and what parameters are supplied - at least if the bug did not corrupt the stack.
However, If you are not too familiar with debugging C or assembly code, you probably want to wait for the developers of perftools to debug this issue.
That looks like Ruby itself is crashing, so chances are, it's a bug. Ruby 1.9.3 is the latest, so you might try that to see if the bug is fixed.

Resources