LoginSignup
6
5

More than 5 years have passed since last update.

バイナリのRPATHの状態を確認する

Posted at

Linuxでバイナリに設定されているRPATHを確認する方法まとめ

事前準備

適当なソースファイルを用意する。

main.cpp
#include <iostream>

int main(int argc, char const* argv[])
{
        std::cout << "aaa" << std::endl;
        return 0;
}
RPATH付きでビルド
$ g++ -Wl,-rpath=/tmp main.cpp 

確認方法

readelf で確認

readelf の Dynamic section にある (RPATH) を参照する

readelfのDynamicSectionを確認
$ readelf -d -w ./a.out
Dynamic section at offset 0xa98 contains 28 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000000f (RPATH)              Library rpath: [/tmp]
<~ 後略 ~>

$ readelf -a -w ./a.out | grep RPATH
 0x000000000000000f (RPATH)              Library rpath: [/tmp]

objdump で確認

objdump でも同様に確認できる

objdumpで確認
$ objdump -x ./a.out | grep RPATH
  RPATH                /tmp

参考

とあるエンジニアの備忘log: Shared Object 入門
ld-linux.soの--inhibit-rpathオプション: RivIs's blog
Is there a way to inspect the current rpath on Linux? - Stack Overflow

6
5
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
6
5