コンパイルの途中の段階で止めてみる
ここでhello.
コンパイルの途中の段階で止めるためのgccのオプションは次のとおりです。
gcc -E | プリプロセッサを通った段階で止める |
---|---|
gcc -S | アセンブラのソースの段階で止める |
gcc -c | リロケータブルオブジェクトファイルの段階で止める |
gcc | 最後までコンパイルする |
図3.
hello.
なお、
hello.
#include <stdio.h>
int
main()
{
printf("Hello World\n");
return 0;
}
.section .rodata
.LC0:
.string "Hello World\n"
.text
.align 4
.globl main
.type main,@function
main:
pushl $.LC0
call printf
xorl %eax,%eax
addl $4,%esp
ret
hello.
(「objdump -d hello.
hello.o: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
0: 68 00 00 00 00 pushl $0x0
5: e8 fc ff ff ff call 6 <main+0x6>
a: 31 c0 xorl %eax,%eax
c: 83 c4 04 addl $0x4,%esp
f: c3 ret
hello
(「objdump -d hello」
hello: file format elf32-i386
Disassembly of section .init:
08048298 <_init>:
8048298: 55 pushl %ebp
:
:
80482c6: c3 ret
Disassembly of section .plt:
080482c8 <.plt>:
80482c8: ff 35 64 94 04 08 pushl 0x8049464
:
:
8048313: e9 b0 ff ff ff jmp 80482c8 <_init+0x30>
Disassembly of section .text:
08048320 <_start>:
8048320: 31 ed xorl %ebp,%ebp
:
:
:
080483c8 <main>:
80483c8: 68 30 84 04 08 pushl $0x8048430
80483cd: e8 36 ff ff ff call 8048308 <_init+0x70>
80483d2: 31 c0 xorl %eax,%eax
80483d4: 83 c4 04 addl $0x4,%esp
80483d7: c3 ret
80483d8: 90 nop
:
:
:
lddコマンドでライブラリを確認
コンパイル済みの実行バイナリファイルは、
実行バイナリファイルが実際にどのライブラリとリンクしているかは、
$ ldd hello
-lc.1 => /usr/lib/libc.so.1.9 ← libc
-ldl.1 => /usr/lib/libdl.so.1.0
OS環境によってはlibcのほか、