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가 없어졌습니다.

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


번호 제목 글쓴이 날짜 조회 수
공지 [공지] 컴파일러 및 가상머신 스터디 관련 Q&A 게시판 입니다. woos 2016.04.09 278
68 LLVM 최적화 패치 제출까지의 순서 정리 marcII 2024.03.19 100
67 스터디 장소 슈민 2016.04.30 114
66 2017년 06/16일 스터디 컴파일러 VM스터디 [1] June 2017.06.16 137
65 [컴파일러/가상머신] 170602 진도 [3] pororo 2017.06.03 151
64 [컴파일러/VM] 170707 스터디 내용 pororo 2017.07.10 153
63 [컴파일러/가상머신] 170526 진도 [4] pororo 2017.05.27 156
62 [컴파일러/VM] 170623 오늘 모임은 취소되었습니다. [3] pororo 2017.06.23 172
61 05/12 컴파일러 스터디 진도 pororo 2017.05.13 182
60 [컴파일러/가상머신] 2회차 진행내용 공유 [8] spike 2017.05.20 209
59 스터디 공간 정리 [3] Kyoo 2016.04.24 263
58 혹시 이 책 보신분 계신지 궁금합니다. [1] marc 2023.02.22 311
57 [컴파일러] 170721 스터디 내용 pororo 2017.07.23 385
56 simplify 에 대해 ChatGPT에게 물어봤습니다. [7] marcII 2023.03.19 681
55 이번 컴파일러 스터디와 관련해서 LLVM에 대해 찾아보았습니다 [1] 자이 2017.05.19 733
54 조언 구합니다. 백창우씨 외 많은 선배님들께 [5] 슈민 2016.06.06 869
53 Compiler (LLVM) 교재 선정 [7] 슈민 2016.04.27 905
52 스터디 교재 관련 의견 취합 [23] 남현우 2016.04.24 1112
51 llvm IR 자이 2017.05.19 1143
50 저번 스터디 토의 내용입니다. 민재원 2013.06.11 1763
XE Login