実行ファイル形式のELFって何?

» 2002年04月10日 00時00分 公開
[木田佳克ITmedia]

この記事は会員限定です。会員登録すると全てご覧いただけます。

 fileコマンドを利用すると、特定のファイルがバイナリであるか、テキスト形式であるかなどが調査できる。

# file /usr/sbin/httpd
/usr/sbin/httpd: ELF 32-bit LSB executable, Intel 80386, version 1, dynamically linked (uses sharedlibs), stripped

 バイナリ形式のファイルを指定した場合、ほとんどの場合で「ELF」という文字列が見られるだろう。

 このELFとは「Executable and Linking Format」の略であり、Red Hatを始めとするLinuxディストリビューションの多くでは標準バイナリ形式として採用されているものだ。

 従来までは「a.out」「COFF」(Common Object File Format)と呼ばれるバイナリフォーマットが占めていたが、ELFでは動的な共有ライブラリの利用と、C++言語のサポートが容易という利点が挙げられる。

 次のように指定すれば、ELF形式のバイナリに含まれるヘッダ情報を知ることが可能だ。表示には、次のように「Intel 80386」などのプラットフォーム情報などが含まれている。

# readelf -h /usr/sbin/httpd
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Intel 80386
  Version:                           0x1
  Entry point address:               0x804fea0
  Start of program headers:          52 (bytes into file)
  Start of section headers:          240940 (bytes into file)
  Flags:                             0x0
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         6
  Size of section headers:           40 (bytes)
  Number of section headers:         24
  Section header string table index: 23

Copyright © ITmedia, Inc. All Rights Reserved.

注目のテーマ