stack smashing detected

프로그램 TEST 중 아래와 같은 오류가 발생했다.

결과는 Core dump.

jonathan@jonathan-laptop:~/workspace/TEST$ ./TEST
*** stack smashing detected ***: ./TEST terminated
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x50)[0xb775c390]
/lib/tls/i686/cmov/libc.so.6(+0xe233a)[0xb775c33a]
./TEST[0x804a2f4]
./TEST[0x8049189]
./TEST[0x8049258]
./TEST[0x8049205]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0xb7690bd6]
./TEST[0x8049081]
======= Memory map: ========
08048000-0804f000 r-xp 00000000 08:05 7344439    /home/jonathan/workspace/TEST/TEST
0804f000-08050000 r–p 00007000 08:05 7344439    /home/jonathan/workspace/TEST/TEST
08050000-08051000 rw-p 00008000 08:05 7344439    /home/jonathan/workspace/TEST/TEST
08051000-080fd000 rw-p 00000000 00:00 0
09a2c000-09a4d000 rw-p 00000000 00:00 0          [heap]
b763d000-b765a000 r-xp 00000000 08:05 4849747    /lib/libgcc_s.so.1
b765a000-b765b000 r–p 0001c000 08:05 4849747    /lib/libgcc_s.so.1
b765b000-b765c000 rw-p 0001d000 08:05 4849747    /lib/libgcc_s.so.1
b7678000-b767a000 rw-p 00000000 00:00 0
b767a000-b77cd000 r-xp 00000000 08:05 4984558    /lib/tls/i686/cmov/libc-2.11.1.so
b77cd000-b77ce000 —p 00153000 08:05 4984558    /lib/tls/i686/cmov/libc-2.11.1.so
b77ce000-b77d0000 r–p 00153000 08:05 4984558    /lib/tls/i686/cmov/libc-2.11.1.so
b77d0000-b77d1000 rw-p 00155000 08:05 4984558    /lib/tls/i686/cmov/libc-2.11.1.so
b77d1000-b77d4000 rw-p 00000000 00:00 0
b77ef000-b77f2000 rw-p 00000000 00:00 0
b77f2000-b77f3000 r-xp 00000000 00:00 0          [vdso]
b77f3000-b780e000 r-xp 00000000 08:05 4855235    /lib/ld-2.11.1.so
b780e000-b780f000 r–p 0001a000 08:05 4855235    /lib/ld-2.11.1.so
b780f000-b7810000 rw-p 0001b000 08:05 4855235    /lib/ld-2.11.1.so
bff3e000-bff53000 rw-p 00000000 00:00 0          [stack]
Aborted (core dumped)

원인 분석을 위해 코어 파일과 함께 gdb를 실행 시켜 보았다.

jonathan@jonathan-laptop:~/workspace/TEST$ gdb -c core TEST
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 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 “i486-linux-gnu”.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>…
Reading symbols from /home/jonathan/workspace/TEST/TEST…done.
[New Thread 5966]

warning: Can’t read pathname for load map: Input/output error.
Reading symbols from /lib/tls/i686/cmov/libc.so.6…(no debugging symbols found)…done.
Loaded symbols for /lib/tls/i686/cmov/libc.so.6
Reading symbols from /lib/ld-linux.so.2…(no debugging symbols found)…done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /lib/libgcc_s.so.1…Reading symbols from /usr/lib/debug/lib/libgcc_s.so.1…done.
done.
Loaded symbols for /lib/libgcc_s.so.1
Core was generated by `./TEST’.
Program terminated with signal 6, Aborted.
#0  0xb77f2430 in __kernel_vsyscall ()
(gdb) where
#0  0xb77f2430 in __kernel_vsyscall ()
#1  0xb76a4651 in raise () from /lib/tls/i686/cmov/libc.so.6
#2  0xb76a7a82 in abort () from /lib/tls/i686/cmov/libc.so.6
#3  0xb76db49d in ?? () from /lib/tls/i686/cmov/libc.so.6
#4  0xb775c390 in __fortify_fail () from /lib/tls/i686/cmov/libc.so.6
#5  0xb775c33a in __stack_chk_fail () from /lib/tls/i686/cmov/libc.so.6
#6  0x0804a2f4 in TestHeadMake () at test.c:515
#7  0x08049189 in TestLog (loglvl=1, title=0x804df59 “TEST”, fmt=0x804df57 “n”) at test.c:196
#8  0x08049258 in StartMessage () at test.c:237
#9  0x08049205 in main (argc=1, argv=0xbff509a4) at test.c:218

문제는 간단했다.

함수 TestHeadMake() 내에서 사용하는 문자열 버퍼 timeStr 의 사이즈가 데이터를 담기에 작았던 것.

바로 찾아서 해결을… 했으면 좋았겠지만 한참을 찾았다…;;

배포판에 설치된 GCC 버전정보

 Linux/Unix 프로그래밍을 하다보면 GCC 버전에 영향을 받는 경우가 있다.

 예를 들면 ACE 라이브러리를 컴파일 할 경우, gcc-4.x 대의 버전에는 컴파일 오류가 발생한다.

 그래서 부득이 gcc/g++ 을 다시 설치하려고 해도 여의치 않는 경우가 많다. 이럴 경우 다른 배포판을 찾아보게 되는데, 여기에 배포판마다 가지고 있는 gcc의 버전 정보를 싣는다.

Distribution Version Compiler version Provided by Date
BeOS R5.1, Zeta gcc 2.9-beos-000224 Yuri Kiryanov 18 June 2004
Debian Release 2.2 gcc 2.95.2 Craig Southeren <craigs@postincrement.com> 15 June 2004
Release 3.0
(Woody)
gcc 2.95.4 Craig Southeren <craigs@postincrement.com> 11 June 2004
Sarge gcc 3.3.5 (final stable version)
gcc 3.3.3 (interim releases)

Kilian Krause <kk@verfaction.de>
15 June 2005
Sid gcc 4.0.1 Kilian Krause <kk@verfaction.de> 19 July 2004
FreeBSD Release 4.8 gcc 2.95.4 Craig Southeren <craigs@postincrement.com> 15 June 2004
Release 4.9
(Stable)
gcc 2.95.4 20020320 Pavel Pavlov <block111@mail.ru> 14 June 2004
Gentoo Stable gcc 3.3.3 Brian Raymond <brian.raymond@dataline.com> 11 June 2004
Mandrake Release 7 (Air) gcc 2.95.2 Craig Southeren <craigs@postincrement.com> 11 June 2004
Release 9.1 gcc 3.2.2 Rene Schallner <rs@rocksolid.at> 11 June 2004
Release 9.2 (FiveStar) gcc 3.3.1 Alexandre Aractingi <aaractingi@libertysurf.fr> 11 June 2004
Release 10.0 gcc 3.3.2 Rene Schallner <rs@rocksolid.at> 11 June 2004
Release 10.1 gcc 3.4.1 Frederic Crozat <fcrozat@mandrakesoft.com> 30 Sep 2004
MontaVista Professional 3.1
for XScale
gcc version 3.3.1 (MontaVista 3.3.1-3.0.10.0300532 2003-12-24) Yuri Kiryanov 18 June 2004
NetBSD Release 1.6.1 gcc 2.95.3 Craig Southeren <craigs@postincrement.com> 15 June 2004
OSX 10.1 Server Edition gcc 2.95.2 Craig Southeren <craigs@postincrement.com> 15 June 2004
10.2 Jaguar gcc 3.1 Malcolm Caldwell <malcolm.caldwell@ntu.edu.au> 11 June 2004
10.2 Server Edition gcc 3.3 20030304 Craig Southeren <craigs@postincrement.com> 15 June 2004
10.3 Panther gcc 3.3 20030304 Brian Raymond <brian.raymond@dataline.com> 22 June 2004
10.4 Tiger gcc 4.0.0
(powerpc-apple-darwin8-gcc-4.0.0)
Hannes Friederich <hannesf@ee.ethz.ch> 15 June 2005
OpenBSD Release 3.4 gcc 2.95.3 Craig Southeren <craigs@postincrement.com> 15 June 2004
Red Hat Release 6.1
(Cartman)
gcc egcs-2.91.66 Bruce Ferrell <bferrell@baywinds.org> 11 June 2004
Release 6.2 (Zoot) gcc egcs-2.91.66 Alexandre Aractingi <aaractingi@libertysurf.fr>  
Release 7.3 (Valhalla) gcc 2.96 20040412 Malcolm Caldwell <malcolm.caldwell@ntu.edu.au> 11 June 2004
Release 8.0A (Second-Edition) gcc 3.2 20020903
(Red Hat Linux 8.0 3.2-7)
Federico Pinna <f.pinna@reitek.com> 11 June 2004
Release 9 (Shrike) gcc 3.2.2
(gcc 2.96 available as “gcc296”)
Craig Southeren <craigs@postincrement.com> 11 June 2004
Advanced Server release 2.1AS/m
(Pensacola)
gcc 2.96 Malcolm Caldwell <malcolm.caldwell@ntu.edu.au> 11 June 2004
Enterprise Linux AS release 3
(Taroon Update 2)
gcc 3.2.3 Malcolm Caldwell <malcolm.caldwell@ntu.edu.au> 11 June 2004
Fedora Core 1 gcc 3.2.2 / gcc 3.2.3 Craig Southeren
<craigs@postincrement.com>
11 June 2004
Fedora Core 2 gcc 3.4.0 / gcc 3.3.3 Derek Smithies <derek@indranet.co.nz> 11 June 2004
Fedora Core 3 gcc 3.4.2 / gcc 4.0.0 Craig Southeren
<craigs@postincrement.com>
14 June 2005
Fedora Core 4 gcc 4.0.0 Craig Southeren
<craigs@postincrement.com>
14 June 2005
Slackware Version 9.1 gcc 3.2.3 Craig Southeren <craigs@postincrement.com> 11 June 2004
Version 10.0 gcc 3.3.4 Craig Southeren <craigs@postincrement.com> 24 June 2004
Suse Release 8 ES on AMD64 gcc 3.2.2 Craig Southeren <craigs@postincrement.com> 15 June 2004
Version 9.0 gcc 3.3.1 Jan Willamowius <jan@willamowius.de> 11 June 2004
Version 9.1 gcc 3.3.3 Kilian Krause <kk@verfaction.de> 17 June 2004
Tornado
(VxWorks)
2.0.1 for ARM gcc 2.7.9-970819
egcs-971225 tornado 2.0
Mark DeBruin
mark.de.bruin@philips.com
11 June 2004
2.1.1 for ARM gcc 2.9-010413 Mark DeBruin
mark.de.bruin@philips.com
11 June 2004
2.1.1 for MIPS gcc 2.96 Mark DeBruin
mark.de.bruin@philips.com
11 June 2004
2.2.1 for MIPS gcc 2.96-mips3264-010729 Mark DeBruin
mark.de.bruin@philips.com
26 August 2004
2.2.1 for XScale gcc 2.9-010413 Mark DeBruin
mark.de.bruin@philips.com
11 June 2004

 출처 : http://www.voxgratia.org/docs/compilers.html#intro

man 페이지만 따로 설치하기..

 노트북에 깔려있던 리눅스에 이상하게 man 3번 섹션, 즉 라이브러리 콜에 대한 man 페이지가 설치되어 있지 않았다.

 평소에는 불편하긴했지만 인터넷의 도움으로 그럭저럭 쓸 수 있었다.

 하지만 매번 맨페이지를 보기 위해 웹 브라우저를 띄우고 검색을 하는 과정이 계속되자 짜증이났다.

 KLDP에서 잠시 검색을 해보니 이내 답을 찾을 수 있었다.

 sudo apt-get install manpages-dev

 명령어 한줄로 간단히 해결되었다.

 이제 귀찮음이여 안녕이다. : )

 원본 : http://kldp.org/node/91231

우분투에서 gcc 컴파일러 관련 라이브러리 설치법

 우분투를 처음 설치하고 컴파일을 하려는 경우

 관련 패키지 혹은 헤더파일이 없다고 에러 메시지가 뜬다.

 이는 특정 패키지를 설치하면 문제가 해결된다.

sudo apt-get install build-essential

 명령어를 입력하면 필요한 패키지들이 자동으로 설치가 된다.