valgrindをソースからインストールする。

はじめに

メモリリークを調べるために、valgrindをインストールしようとした。しかし、[sudo apt-get install valgrind]でインストールしたら、valgrind のコマンドでこける。また、ソースから再インストールしようとしたら、configureでこける。以下に、valgrindがきちんと使えるようになるまでの作業を示す。

作業

configure が失敗する

configure 実行結果を以下に示す。

andre@andre-VirtualBox:~/work/valgrind/valgrind-3.6.1$ !./configure
./configure --prefix=/home/andre/local
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking whether ln -s works... yes
checking for gcc... ccache gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether ccache gcc accepts -g... yes
checking for ccache gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of ccache gcc... gcc3
checking whether ccache gcc and cc understand -c and -o together... yes
checking how to run the C preprocessor... ccache gcc -E
checking whether we are using the GNU C++ compiler... yes
checking whether ccache g++ accepts -g... yes
checking dependency style of ccache g++... gcc3
checking for ranlib... ranlib
checking for a sed that does not truncate output... /bin/sed
checking for ar... /usr/bin/ar
checking for perl... /usr/bin/perl
checking for gdb... /usr/bin/gdb
checking dependency style of ccache gcc... gcc3
checking for diff -u... yes
checking for a supported version of gcc... ok (4.6.1)
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for a supported CPU... ok (i686)
checking for a 64-bit only build... no
checking for a 32-bit only build... no
checking for a supported OS... ok (linux-gnu)
checking for the kernel version... unsupported (3.0.0-17-generic)
configure: error: Valgrind works on kernels 2.4, 2.6

Ubuntu 11.10 にインストールされている kernelのバージョンが2.4 or 2.6 ではないことが原因のようだ。
確かに違う。

andre@andre-VirtualBox:~/work/valgrind/valgrind-3.6.1$ uname -r
3.0.0-17-generic

configure にパッチをあてる

Issue 10 - avalanche - Configure said 'kernel version... unsupported' - Avalanche is a dynamic defect detection tool that generates "inputs of death" - input data reproducing critical bugs and vulnerabilities in the analysed program. - Google Project Hosting

ここからパッチをダウンロードしてパッチをあてる。

andre@andre-VirtualBox:~/work/valgrind/valgrind-3.6.1$ patch -i valgrind_configure_patch
andre@andre-VirtualBox:~/work/valgrind/valgrind-3.6.1$ cd ../
andre@andre-VirtualBox:~/work/valgrind$ ln -s valgrind-3.6.1 valgrind
andre@andre-VirtualBox:~/work/valgrind$ patch -p0 -i patch.diff

configure を生成する

下記コマンドを実行し、configureファイルを生成する。

andre@andre-VirtualBox:~/work/valgrind/valgrind-3.6.1$ autoconf configure.in

configureを実行する。

下記コマンドを実行する。

andre@andre-VirtualBox:~/work/valgrind/valgrind-3.6.1$ ./configure --prefix=/home/andre/local

prefixオプションは各自で設定する。なくてもいい。

make & install

※ ccache を用いてビルドすると、エラーになる。エラーログは取得していない

andre@andre-VirtualBox:~/work/valgrind/valgrind-3.6.1$ make
andre@andre-VirtualBox:~/work/valgrind/valgrind-3.6.1$ sudo make install
andre@andre-VirtualBox:~/work/valgrind/valgrind-3.6.1$ export PATH=/home/andre/local/bin:$PATH
andre@andre-VirtualBox:~/work/valgrind/valgrind-3.6.1$ valgrind --help ★helpが表示されれば、OK!