강좌 & 팁
글 수 2,412
2011.06.09 14:26:54 (*.138.143.120)
44116
1. gcc 에서 컴파일된 결과 물인 *.o 도 elf 포맷인가요?
예... 컴파일 된 오브젝트 파일도 elf 포맷입니다.
다음과 같이 test.c 를 만든후 컴파일하고 readelf 를 이용하여 검토해 봅시다.
# cat test.c
#include <stdio.h>
int count = 3;
int test_function( int a )
{
int b;
int c;
b = a + 1;
c = a * 4 >> 4;
return b+c;
}
frog@eabi:tmp$
# gcc -c test.c
frog@eabi:tmp$ readelf -a test.o
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: REL (Relocatable file)
Machine: Intel 80386
Version: 0x1
Entry point address: 0x0
Start of program headers: 0 (bytes into file)
Start of section headers: 204 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0
Size of section headers: 40 (bytes)
Number of section headers: 9
Section header string table index: 6
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .text PROGBITS 00000000 000034 000026 00 AX 0 0 4
[ 2] .data PROGBITS 00000000 00005c 000004 00 WA 0 0 4
[ 3] .bss NOBITS 00000000 000060 000000 00 WA 0 0 4
[ 4] .comment PROGBITS 00000000 000060 000024 01 MS 0 0 1
[ 5] .note.GNU-stack PROGBITS 00000000 000084 000000 00 0 0 1
[ 6] .shstrtab STRTAB 00000000 000084 000045 00 0 0 1
[ 7] .symtab SYMTAB 00000000 000234 000090 10 8 7 4
[ 8] .strtab STRTAB 00000000 0002c4 00001c 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
There are no section groups in this file.
There are no program headers in this file.
There are no relocations in this file.
There are no unwind sections in this file.
Symbol table '.symtab' contains 9 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000000 0 FILE LOCAL DEFAULT ABS test.c
2: 00000000 0 SECTION LOCAL DEFAULT 1
3: 00000000 0 SECTION LOCAL DEFAULT 2
4: 00000000 0 SECTION LOCAL DEFAULT 3
5: 00000000 0 SECTION LOCAL DEFAULT 5
6: 00000000 0 SECTION LOCAL DEFAULT 4
7: 00000000 4 OBJECT GLOBAL DEFAULT 2 count
8: 00000000 38 FUNC GLOBAL DEFAULT 1 test_function
No version information found in this file.
frog@eabi:tmp$
2. elf 포맷 파일을 다루는 라이브러리가 있을까요?
우선 LibElf 는 다음 위치에 있습니다. BSD 라이센스라서 괜찮은 것 같습니다.
다음 위치에 가면 찾을 수 있습니다.
http://wiki.freebsd.org/LibElf
3. 괜찮은 자료
기사 : (영문)
http://developers.sun.com/solaris/articles/elf.html
라이브러리 사용 예제
http://sourceforge.net/projects/elftoolchain/files/Documentation/libelf-by-example/