3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Ruby の gem の中の .bundle ファイルを確認した話

Last updated at Posted at 2021-04-04

Ruby の *.bundle ファイルを確認した話

gem が拡張ライブラリの場合,例えば MacOS であれば bundleという拡張子のファイルができる.

$ file vendor/bundle/ruby/2.6.0/gems/greenmat-3.5.1.1/lib/greenmat.bundle
vendor/bundle/ruby/2.6.0/gems/greenmat-3.5.1.1/lib/greenmat.bundle: Mach-O 64-bit bundle x86_64

見ての通り,Mach-O 64-bit bundle x86_64 というファイルフォーマットになっている.

ダイナミックリンクライブラリ

bundle ファイルには,ダイナミックリンクライブラリがリンクされている場合がある.

$ otool -L vendor/bundle/ruby/2.6.0/gems/greenmat-3.5.1.1/lib/greenmat.bundle
vendor/bundle/ruby/2.6.0/gems/greenmat-3.5.1.1/lib/greenmat.bundle:
        /usr/local/opt/rbenv/versions/2.6.3/lib/libruby.2.6.dylib (compatibility version 2.6.0, current version 2.6.3)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1)

今回は,Ruby のライブラリだったけど,他の依存ライブラリ(libmysql,libssh とか) の場合もありえる.

見ての通りファイル名にバージョン番号が含まれている場合があるので,バージョンが変わる(=ファイル名が変わる) と面倒になる可能性がある.

Case

例えば,ライブラリとしては互換性があるけど,ファイル名が変わってしまった場合は,同名ファイルを作る(シンボリックリンクとか) ことで解決できるかもしれないし,
互換性が無い場合は,.bundleファイルを再作成した方がいいかもしれない.

Linux だと

ちなむと

$ file /usr/local/bundle/gems/greenmat-3.5.1.1/lib/greenmat.so
/usr/local/bundle/gems/greenmat-3.5.1.1/lib/greenmat.so: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=43f2c67f9b7512be3bc1554841f662413140d434, with debug_info, not stripped
$ ldd /usr/local/bundle/gems/greenmat-3.5.1.1/lib/greenmat.so
        linux-vdso.so.1 (0x00007ffc0b58e000)
        libruby.so.2.6 => /usr/local/lib/libruby.so.2.6 (0x00007f73e54a6000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f73e531a000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f73e5159000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f73e4f3b000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f73e4f1a000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f73e4f10000)
        libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f73e4e8b000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f73e4e86000)
        libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f73e4e4c000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f73e581e000)

付録

もうちょっと色々出る

$ otool -l /usr/bin/diff3 | awk '/LC_LOAD_DY/,/name/{print}'
          cmd LC_LOAD_DYLINKER
      cmdsize 32
         name /usr/lib/dyld (offset 12)
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name /usr/lib/libSystem.B.dylib (offset 24)

Refs

3
0
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
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?