So far I've writen this.
Code: Select all
s_node_t *fsnode = finddir_fs(fs_root, "test.o");
Elf32_Ehdr n;
read_fs(fsnode, 0, sizeof(Elf32_Ehdr), &n);
ASSERT(n.e_ident[0] == 0x7f);
ASSERT(n.e_ident[1] == 'E');
ASSERT(n.e_ident[2] == 'L');
ASSERT(n.e_ident[3] == 'F');
ASSERT(n.e_type == 1);
int i;
for(i=0;i<n.e_shnum;i++){
Elf32_Shdr r;
read_fs(fsnode, n.e_shoff + i * n.e_phentsize, sizeof(Elf32_Shdr), &r);
if(r.sh_addr != 0){
printf("Section %d to be loaded from %d to %d (%d bytes)\n", i, r.sh_offset, r.sh_addr, r.sh_size);
}
}
Code: Select all
readelf test.o -S
There are 9 section headers, starting at offset 0xd4:
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 000031 00 AX 0 0 4
[ 2] .data PROGBITS 00000000 000068 000000 00 WA 0 0 4
[ 3] .bss NOBITS 00000000 000068 000000 00 WA 0 0 4
[ 4] .comment PROGBITS 00000000 000068 000025 00 0 0 1
[ 5] .note.GNU-stack PROGBITS 00000000 00008d 000000 00 0 0 1
[ 6] .shstrtab STRTAB 00000000 00008d 000045 00 0 0 1
[ 7] .symtab SYMTAB 00000000 00023c 000080 10 8 7 4
[ 8] .strtab STRTAB 00000000 0002bc 00000d 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)
-----------
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
[b] Entry point address: 0x0[/b]
Start of program headers: 0 (bytes into file)
Start of section headers: 212 (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
Am I compiling the c incorrectly? I'm using cc -nostdlib -nostdinc -fno-builtin -fno-stack-protector -c -o test.o test.c
Thanks,
Gonzalo