centos 5에서 boost, pthread를 포함해서 static link를 하면 계속 segfault가 발생 하더라고요.

centos6, ubuntu13 에서는 문제없이 실행이 잘 됩니다.

서비스용으로 centos5를 사용하고 있어서 삽실을 시작 했습니다.-_-


gdb내용을 보면...

Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? () (gdb) bt 
#0 0x00000000 in ?? ()
#1 0x080a4adf in __cxa_guard_release ()
#2 0x0804a867 in asio::system_category () at /root/asio-1.5.3/include/asio/impl/error_code.ipp:85 
#3 0x0804a895 in asio::error::get_system_category () at /root/asio-1.5.3/include/asio/error.hpp:214 
#4 0x0804832c in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at /root/asio-1.5.3/include/asio/error.hpp:242 
#5 0x0804850b in global constructors keyed to main() () at client.cpp:60 #6 0x0812891b in __do_global_ctors_aux () 
#7 0x08048109 in _init ()
#8 0x080b8882 in __libc_csu_init ()
#9 0x080b8261 in __libc_start_main () 
#10 0x08048131 in _start ()


objdump 내용.

80a4a90 <__cxa_guard_release>:
80a4a90: 55 push %ebp 
80a4a91: 89 e5 mov %esp,%ebp 
80a4a93: 83 ec 18 sub $0x18,%esp 
80a4a96: 89 5d f8 mov %ebx,0xfffffff8(%ebp) 
80a4a99: e8 a4 fb ff ff call 80a4642 <__i686.get_pc_thunk.bx> 
80a4a9e: 81 c3 6a 62 0c 00 add $0xc626a,%eb 
80a4aa4: 89 75 fc mov %esi,0xfffffffc(%ebp) 
80a4aa7: 8b 75 08 mov 0x8(%ebp),%esi 
80a4aaa: 8b 83 e8 ff ff ff mov 0xffffffe8(%ebx),%eax 
80a4ab0: 85 c0 test %eax,%eax 
80a4ab2: 75 11 jne 80a4ac5 <__cxa_guard_release+0x35> 
80a4ab4: c6 46 01 00 movb $0x0,0x1(%esi) 
80a4ab8: c6 06 01 movb $0x1,(%esi) 
80a4abb: 8b 5d f8 mov 0xfffffff8(%ebp),%ebx 
80a4abe: 8b 75 f mov 0xfffffffc(%ebp),%esi 
80a4ac1: 89 ec mov %ebp,%esp 
80a4ac3: 5d pop %ebp 
80a4ac4: c3 ret 
80a4ac5: e8 76 fd ff ff call 80a4840 <_ZN72_GLOBAL__N_.._.._.._.._libstdc___v3_libsupc___guard. 
80a4aca: c6 46 01 00 movb $0x0,0x1(%esi) 
80a4ace: 8d 83 f8 34 00 00 lea 0x34f8(%ebx),%eax 
80a4ad4: c6 06 01 movb $0x1,(%esi) 
80a4ad7: 89 04 24 mov %eax,(%esp) 
80a4ada: e8 21 b5 f5 f7 call 0 <_nl_current_LC_CTYPE> 
80a4adf: 8b 5d f8 mov 0xfffffff8(%ebp),%ebx 
80a4ae2: 8b 75 fc mov 0xfffffffc(%ebp),%esi 
80a4ae5: 89 ec mov %ebp,%esp 
80a4ae7: 5d pop %ebp 
80a4ae8: e9 83 fd ff ff jmp 80a4870 <_ZN72_GLOBAL__N_.._.._.._.._libstdc___v3_libsupc___guard. 
80a4aed: 90 nop 
80a4aee: 90 nop 
80a4aef: 90 nop



objdump를 해보니 "call 0" 이 있고, 이 부분이 문제가 있어 보여서 더 추적을 했습니다.

__cxa_guard_release 함수는 libsu++에 있는것이고 이건 Libstdc++에 있는 것이라서 libstdc++를 확인 해봤습니다.


libstdc++를 dump 해보니 위 "call 0" 위치에 아래같은 내용이 있네요.

call ae0a24 <pthread_cond_broadcast@plt> 



문제가 뭘까 열심히 찾다가 해결 방법을 찾았습니다.

http://gcc.gnu.org/ml/gcc-help/2010-05/msg00029.html

pthread를 링크할 때 아래처럼 하면 된다네요.

"-Wl,--whole-archive -lpthread -Wl,--no-whole-archive"

위 옵션으로 pthread를 링크 하니 segfault가 없어졌습니다.

이 옵션이 뭔지,, 왜 저런 상황이 발생 하는지는 아직도 정확히 이해는 못하겠네요.. 음


XE Login