LoginSignup
7
4

More than 5 years have passed since last update.

PatchELFのビルド

Posted at

PatchELF はロードモジュールのELF インタープリターや RPATH の表示、変更ができるツールです。

ソースからビルドするために、あらかじめビルドに必要なパッケージをインストールしておきます。
ビルドには g++ が必要ですので、gcc だけでなく g++ もしくは gcc-c++ など g++ コンパイラのパッケージもインストールしてください。

ソースを取得して展開します。

$ wget http://nixos.org/releases/patchelf/patchelf-0.8/patchelf-0.8.tar.bz2
$ tar xfa patchelf-0.8.tar.bz2
$ cd patchelf-0.8

configure を実行します。

$ ./configure --prefix=/usr/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 for style of include used by make... GNU
checking for gcc... 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 gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking dependency style of gcc... gcc3
checking whether gcc and cc understand -c and -o together... yes
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking dependency style of g++... gcc3
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating tests/Makefile
config.status: creating patchelf.spec
config.status: executing depfiles commands

make コマンドを実行します。

$ make
Making all in src
make[1]: Entering directory `/src/patchelf-0.8/src'
g++ -DPACKAGE_NAME=\"patchelf\" -DPACKAGE_TARNAME=\"patchelf\" -DPACKAGE_VERSION=\"0.8\" -DPACKAGE_STRING=\"patchelf\ 0.8\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"patchelf\" -DVERSION=\"0.8\" -I.     -g -O2 -MT patchelf.o -MD -MP -MF .deps/patchelf.Tpo -c -o patchelf.o patchelf.cc
mv -f .deps/patchelf.Tpo .deps/patchelf.Po
g++  -g -O2   -o patchelf patchelf.o
make[1]: Leaving directory `/src/patchelf-0.8/src'
Making all in tests
make[1]: Entering directory `/src/patchelf-0.8/tests'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/src/patchelf-0.8/tests'
make[1]: Entering directory `/src/patchelf-0.8'
make[1]: Nothing to be done for `all-am'.
make[1]: Leaving directory `/src/patchelf-0.8'

インストールします。

$ sudo make install
Making install in src
make[1]: Entering directory `/src/patchelf-0.8/src'
make[2]: Entering directory `/src/patchelf-0.8/src'
 /bin/mkdir -p '/usr/local/bin'
  /usr/bin/install -c patchelf '/usr/local/bin'
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/src/patchelf-0.8/src'
make[1]: Leaving directory `/src/patchelf-0.8/src'
Making install in tests
make[1]: Entering directory `/src/patchelf-0.8/tests'
make[2]: Entering directory `/src/patchelf-0.8/tests'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/src/patchelf-0.8/tests'
make[1]: Leaving directory `/src/patchelf-0.8/tests'
make[1]: Entering directory `/src/patchelf-0.8'
make[2]: Entering directory `/src/patchelf-0.8'
make[2]: Nothing to be done for `install-exec-am'.
 /bin/mkdir -p '/usr/local/share/doc/patchelf'
 /usr/bin/install -c -m 644 README '/usr/local/share/doc/patchelf'
 /bin/mkdir -p '/usr/local/share/man/man1'
 /usr/bin/install -c -m 644 patchelf.1 '/usr/local/share/man/man1'
make[2]: Leaving directory `/src/patchelf-0.8'
make[1]: Leaving directory `/src/patchelf-0.8'

できあがり。

$ /usr/local/bin/patchelf
syntax: /usr/local/bin/patchelf
  [--set-interpreter FILENAME]
  [--print-interpreter]
  [--set-rpath RPATH]
  [--shrink-rpath]
  [--print-rpath]
  [--force-rpath]
  [--remove-needed LIBRARY]
  [--debug]
  [--version]
  FILENAME
$ printf '#include <stdio.h>\nmain() {printf("hello world\\n");}\n' >hello.c
$ cat hello.c 
#include <stdio.h>
main() {printf("hello world\n");}
$ gcc hello.c 
$ /usr/local/bin/patchelf --print-rpath a.out 
$ /usr/local/bin/patchelf --set-rpath /usr/local/lib a.out 
$ /usr/local/bin/patchelf --print-rpath a.out 
/usr/local/lib
7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4