昨日の続き(nacl)

今日は少しばかり早く帰ってきた。よって、ビールと焼酎を思わず呑んでしまう。
そこで、少し酔いをさましてから、昨日の続きのnaclいじりだ。

http://nativeclient.googlecode.com/svn/trunk/nacl/googleclient/native_client/documentation/getting_started.html#make

に書かれた「Use make to compile and run standalone examples (Linux or Mac)」についてあれこれいじってみる。

文章を読んでみると、naclではビルドツールにはmakeでなくSConsなるものを使うらしい。
これを使ってサンプルプログラムをコンパイルできるようだ.

また、ビルドできるアプリには2つのタイプがあるらしい。

[standalone application]
ネイティブなOS上で実行可能なバイナリを作れる。

make debug run

でビルドできる。

例えば、nacl/googleclient/native_client/tests/earth に移動するとサンプルプログラムの一つがある。
このディレクトリで"make debug run"とコマンドを叩くと、地球がくるくる自転する絵が表示されると思う。
コマンド実行後、ディレクトリの中をみると

[eria@localhost earth]$ ls
Makefile SConscript.nacl earth.html earth_image.inc
README.txt earth.cc earth_debug run.py

となっていて「earth_debug」が生成されていることがわかる。

生成されたファイルについて調べてみる。

[eria@localhost earth]$ file earth_debug
earth_debug: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped

ホントにネイティブコードだ.

[ネイティブクライアント]
こいつがブラウザで実行できるイメージと思われる。

make release nacl run

で作れる.
ちなみにmake release nacl runを実行したあとでmake cleanしても問題ない。

ネイティブクライアントは python run.py で実行できるようだ.
このPythonコードではnacl/googleclient/native_client/scons-out/nacl/stagingにあるファイルを実行している。

さて、このディレクトリには何があるのか
いろいろあるが、目を引くのはnexe拡張子形式のファイル。
これらのファイル群からそれらしいファイルを見つける。

@localhost staging]$ ls earth*
earth.html earth.nexe

[eria@localhost staging]$ file earth.nexe
earth.nexe: ELF 32-bit LSB executable, Intel 80386, version 1, statically linked, not stripped

ほほう。こいつはstatic linkされた実行形式ファイルか。

おそらくは
1.実効速度的な問題
2.セキュリティ上の問題で、Sand Box外からバイナリをロードしたくない
という2点の理由があると思われる。