kzkの日記: ELF勉強会 - osdev-jに触発されて -
以前から compile→link の過程には非常に興味があった。
良い機会だからちょっとマニアックにいってみようかな。
今回先生となって頂くのは「Linkers and Loaders」。
Webで読めます。
Linkers and Loaders : http://www.iecc.com/linker/
---
中段からELFについての記述が始まる。
こっから読んでみませう。
http://www.iecc.com/linker/linker03.html
-
いきなり読み始めるのはあふぉうなのでまずは段落構成を見る。
Unix ELF
Relocatable files
ELF executable files
ELF summary
-
まずは冒頭。
ELF files come in three slightly different flavors: relocatable, executable, and shared object. Relocatable files are created by compilers and assemblers but need to be processed by the linker before running. Executable files have all relocation done and all symbols resolved except perhaps shared library symbols to be resolved at runtime. Shared objects are shared libraries, containing both symbol information for the linker and directly runnable code for runtime.
段落構成から見ても結局は relocatable file としても excutable file としても存在できるということだろうぐらいな感じかな。
「Relocate」という作業の内容がよく分からない。
http://www.iecc.com/linker/linkerfig03-10.html
この図を見てきになること。
section table headerが何故後部に位置しているのだろう?
「Relocate」によって section の情報が逐一変わってしまうから、変更後に最後に section の情報をつけたすということなのかな。
わかんね。
次は ELF header の仕様。
char pad[9]; short filetype;
// file type: 1 = relocatable, 2 = executable,
// 3 = shared object, 4 = core image
これに注目。
どうやらさっきの予想はちょっと甘かったみたいですな。
現実には4種類のELFが存在するということですか。
-
次にまとめを読んでみる。
ELF is a moderately complex format, but it serves its purposes well.
ELFは適度に複雑な形式ではあるが目的をうまくはたしている。
It's a flexible enough relocatable format to support C++, while being an efficient executable format for a virtual memory system with dynamic linking, and makes it easy to map executable pages directly into the program address space.
ダイナミックリンキングを用いた仮想メモリシステムのための効果的な実行形式である一方、C++をサポートするのに十分なぐらい柔軟である。
またELFによって、プログラムアドレス空間に直接 excutable pages を簡単に配置できる。
It also permits cross-compilation and cross-linking from one platform to another, with enough information in each ELF file to identify the target architecture and byte order.
ターゲットとなるマシンアーキテクチャとバイトの順番を判別するための十分な情報をそれぞれのELFファイルのなかに保持したまま、色々なプラットフォーム位におけるクロスコンパイル、そしてクロスリンキングも可能にする。
ふぅむ。
よくわからんな。
しかも悪い点とか何も書いてない辺り疑わしい。
まぁそれはいいとして、ようは「柔軟」ってことですな(そうなのか?
-
今日はこの辺りで終了。
お塾でクーラー直撃で風邪を引いてしまった模様。くしゅん。
-
Relocateって調べてもいまいち分からんなぁ。
ってかそもそもOSはプログラムを実行する時にどういう処理をしてるのだぁ?
-
先は長そうだ。
ELF勉強会 - osdev-jに触発されて - More ログイン