Skip to content

Instantly share code, notes, and snippets.

@knknkn1162
Last active June 14, 2018 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knknkn1162/ea1ab38081ceadc0d0c3d71db9418ca2 to your computer and use it in GitHub Desktop.
Save knknkn1162/ea1ab38081ceadc0d0c3d71db9418ca2 to your computer and use it in GitHub Desktop.
## Note) The structure of ELF header, Section header and section is same as the relocatable objectfile, hello.o. See https://gist.github.com/knknkn1162/58325c37aa9f6554ca73c931012b0f1d in detail.
# hexdump -vC res
# ELF header
00000000 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 |.ELF............|
00000010 02 00 3e 00 01 00 00 00 b0 00 40 00 00 00 00 00 |..>.......@.....|
00000020 40 00 00 00 00 00 00 00 40 02 00 00 00 00 00 00 |@.......@.......|
00000030 00 00 00 00 40 00 38 00 02 00 40 00 06 00 05 00 |....@.8...@.....|
# program header
# readelf -l res # or you can do this by `objdump -p res`
Section to Segment mapping:
Segment Sections...
00 .text
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000
0x00000000000000d7 0x00000000000000d7 R E 0x200000
# vaddr(VMA) .. virtual memory address
# paddr(LMA) .. physical(load) memory address
# 00 segment header (contains .text section)
+-----+-----+-----------+-----------------------+
|type |flags |offset |
+-----+-----+-----------+-----------------------+
0x00000040 |01 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00| |................|
+-----+-----+-----------+-----------------------+
|vaddr |paddr |
+-----+-----+-----------+-----------------------+
0x00000050 |00 00 40 00 00 00 00 00 00 00 40 00 00 00 00 00| |..@.......@.....|
+-----+-----+-----------+-----------------------+
|filesz |memsz |
+-----+-----+-----------+-----------------------+
0x00000060 |d7 00 00 00 00 00 00 00 d7 00 00 00 00 00 00 00| |................|
+-----+-----+-----------+-----------------------+
|p_align |
+-----+-----+-----------+-----------------------+
0x00000070 |00 00 20 00 00 00 00 00| |.. ..... |
Section to Segment mapping:
Segment Sections...
01 .data
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
LOAD 0x00000000000000d8 0x00000000006000d8 0x00000000006000d8
0x000000000000000d 0x000000000000000d RW 0x200000
# 01 segment header (contains .data section)
+-----+-----+-----------+-----------+-----------+
|type |flags |
+-----+-----+-----------+-----------+-----------+
0x00000070 |01 00 00 00 06 00 00 00| | ........|
+-----+-----+-----------+-----------------------+
|offset |vaddr |
+-----+-----+-----------+-----------------------+
0x00000080 d8 00 00 00 00 00 00 00 d8 00 60 00 00 00 00 00| |..........`.....|
+-----+-----+-----------+-----------------------+
|paddr |filesz |
+-----+-----+-----------+-----------------------+
0x00000090 |d8 00 60 00 00 00 00 00 0d 00 00 00 00 00 00 00| |..`.............|
+-----+-----+-----------+-----------------------+
|memsz |p_align |
+-----+-----+-----------+-----------------------+
0x000000a0 |0d 00 00 00 00 00 00 00 00 00 20 00 00 00 00 00| |.......... .....|
+-----+-----+-----------+-----------------------+
# .text, .data, .shstrtab section
000000b0 b8 01 00 00 00 bf 01 00 00 00 48 be d8 00 60 00 |..........H...`.|
000000c0 00 00 00 00 ba 0d 00 00 00 0f 05 b8 3c 00 00 00 |............<...|
000000d0 bf 00 00 00 00 0f 05 00 48 65 6c 6c 6f 20 77 6f |........Hello wo|
000000e0 72 6c 64 21 0a 00 00 00 00 00 00 00 00 00 00 00 |rld!............|
000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000100 00 00 00 00 03 00 01 00 b0 00 40 00 00 00 00 00 |..........@.....|
# 6 Section headers
00000110 00 00 00 00 00 00 00 00 00 00 00 00 03 00 02 00 |................|
00000120 d8 00 60 00 00 00 00 00 00 00 00 00 00 00 00 00 |..`.............|
00000130 01 00 00 00 04 00 f1 ff 00 00 00 00 00 00 00 00 |................|
00000140 00 00 00 00 00 00 00 00 0b 00 00 00 00 00 02 00 |................|
00000150 d8 00 60 00 00 00 00 00 00 00 00 00 00 00 00 00 |..`.............|
00000160 17 00 00 00 00 00 f1 ff 0d 00 00 00 00 00 00 00 |................|
00000170 00 00 00 00 00 00 00 00 2c 00 00 00 10 00 01 00 |........,.......|
00000180 b0 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00 |..@.............|
00000190 27 00 00 00 10 00 02 00 e5 00 60 00 00 00 00 00 |'.........`.....|
000001a0 00 00 00 00 00 00 00 00 33 00 00 00 10 00 02 00 |........3.......|
000001b0 e5 00 60 00 00 00 00 00 00 00 00 00 00 00 00 00 |..`.............|
000001c0 3a 00 00 00 10 00 02 00 e8 00 60 00 00 00 00 00 |:.........`.....|
000001d0 00 00 00 00 00 00 00 00 00 68 65 6c 6c 6f 2e 61 |.........hello.a|
000001e0 73 6d 00 68 65 6c 6c 6f 5f 77 6f 72 6c 64 00 68 |sm.hello_world.h|
000001f0 65 6c 6c 6f 5f 77 6f 72 6c 64 5f 6c 65 6e 00 5f |ello_world_len._|
00000200 5f 62 73 73 5f 73 74 61 72 74 00 5f 65 64 61 74 |_bss_start._edat|
00000210 61 00 5f 65 6e 64 00 00 2e 73 79 6d 74 61 62 00 |a._end...symtab.|
00000220 2e 73 74 72 74 61 62 00 2e 73 68 73 74 72 74 61 |.strtab..shstrta|
00000230 62 00 2e 74 65 78 74 00 2e 64 61 74 61 00 00 00 |b..text..data...|
00000240 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000250 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000260 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000270 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000280 1b 00 00 00 01 00 00 00 06 00 00 00 00 00 00 00 |................|
00000290 b0 00 40 00 00 00 00 00 b0 00 00 00 00 00 00 00 |..@.............|
000002a0 27 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |'...............|
000002b0 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000002c0 21 00 00 00 01 00 00 00 03 00 00 00 00 00 00 00 |!...............|
000002d0 d8 00 60 00 00 00 00 00 d8 00 00 00 00 00 00 00 |..`.............|
000002e0 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000002f0 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000300 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 |................|
00000310 00 00 00 00 00 00 00 00 e8 00 00 00 00 00 00 00 |................|
00000320 f0 00 00 00 00 00 00 00 04 00 00 00 06 00 00 00 |................|
00000330 08 00 00 00 00 00 00 00 18 00 00 00 00 00 00 00 |................|
00000340 09 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 |................|
00000350 00 00 00 00 00 00 00 00 d8 01 00 00 00 00 00 00 |................|
00000360 3f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |?...............|
00000370 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000380 11 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 |................|
00000390 00 00 00 00 00 00 00 00 17 02 00 00 00 00 00 00 |................|
000003a0 27 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |'...............|
000003b0 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000003c0
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment