The first chapter of the New Testament.
Direct consequence of Euclid's formula.
Section type:
sh_type == SHT_RELA
.Common name: "relocation section".
.rela.text
holds relocation data which says how the address should be modified when the final executable is linked. This points to bytes of the text area that must be modified when linking happens to point to the correct memory locations.Basically, it translates the object text containing the placeholder 0x0 address:to the actual executable code containing the final 0x6000d8:
a: 48 be 00 00 00 00 00 movabs $0x0,%rsi
11: 00 00 00
4000ba: 48 be d8 00 60 00 00 movabs $0x6000d8,%rsi
4000c1: 00 00 00
It was pointed to by
sh_info
= 6
of the .symtab
section.readelf -r hello_world.o
outputs:Relocation section '.rela.text' at offset 0x3b0 contains 1 entries:
Offset Info Type Sym. Value Sym. Name + Addend
00000000000c 000200000001 R_X86_64_64 0000000000000000 .data + 0
The section does not exist in the executable.
The actual bytes are:
00000370 0c 00 00 00 00 00 00 00 01 00 00 00 02 00 00 00 |................|
00000380 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
The
struct
represented is:typedef struct {
Elf64_Addr r_offset;
Elf64_Xword r_info;
Elf64_Sxword r_addend;
} Elf64_Rela;
So:
- 370 0:
r_offset
= 0xC: address into the.text
whose address this relocation will modify - 370 8:
r_info
= 0x200000001. Contains 2 fields:ELF64_R_TYPE
= 0x1: meaning depends on the exact architecture.ELF64_R_SYM
= 0x2: index of the section to which the address points, so.data
which is at index 2.
The AMD64 ABI says that type1
is calledR_X86_64_64
and that it represents the operationS + A
where:This address is added to the section on which the relocation operates. - 380 0:
r_addend
= 0
Holds strings for the symbol table.
This section has
sh_type == SHT_STRTAB
.It is pointed to by outputs:
sh_link == 5
of the .symtab
section.readelf -x .strtab hello_world.o
Hex dump of section '.strtab':
0x00000000 0068656c 6c6f5f77 6f726c64 2e61736d .hello_world.asm
0x00000010 0068656c 6c6f5f77 6f726c64 0068656c .hello_world.hel
0x00000020 6c6f5f77 6f726c64 5f6c656e 005f7374 lo_world_len._st
0x00000030 61727400 art.
This implies that it is an ELF level limitation that global variables cannot contain NUL characters.
Now that we've done one section manually, let's graduate and use the
readelf -S
of the other sections: [Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 2] .text PROGBITS 0000000000000000 00000210
0000000000000027 0000000000000000 AX 0 0 16
.text
is executable but not writable: if we try to write to it Linux segfaults. Let's see if we really have some code there:objdump -d hello_world.o
hello_world.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <_start>:
0: b8 01 00 00 00 mov $0x1,%eax
5: bf 01 00 00 00 mov $0x1,%edi
a: 48 be 00 00 00 00 00 movabs $0x0,%rsi
11: 00 00 00
14: ba 0d 00 00 00 mov $0xd,%edx
19: 0f 05 syscall
1b: b8 3c 00 00 00 mov $0x3c,%eax
20: bf 00 00 00 00 mov $0x0,%edi
25: 0f 05 syscall
If we grep
b8 01 00 00
on the hd
, we see that this only occurs at 00000210
, which is what the section says. And the Size is 27, which matches as well. So we must be talking about the right section.The most interesting part is line to pass the address of the string to the system call. Currently, the This modification is possible because of the data of the
a
which does:movabs $0x0,%rsi
0x0
is just a placeholder. After linking happens, it will be modified to contain:4000ba: 48 be d8 00 60 00 00 movabs $0x6000d8,%rsi
.rela.text
section.See also: Ciro Santilli's minor projects.
Cool that there is actually a page for a change: www.ox.ac.uk/students/academic/exams/timetables e.g. working in 2024: web.archive.org/web/20240305013807/https://www.ox.ac.uk/students/academic/exams/timetables
There are unlisted articles, also show them or only show them.