When I disassemble a function, I encounter from time to time an expression of the form %reg:value. Typically, I encounter this syntax when I activate the canaries in GCC (-fstack-protector), as in the following example:
(gdb) disas
Dump of assembler code for function foo:
0x000000000040057c <+0>: push %rbp
0x000000000040057d <+1>: mov %rsp,%rbp
0x0000000000400580 <+4>: sub $0x20,%rsp
0x0000000000400584 <+8>: mov %edi,-0x14(%rbp)
=> 0x0000000000400587 <+11>: mov %fs:0x28,%rax
0x0000000000400590 <+20>: mov %rax,-0x8(%rbp)
0x0000000000400594 <+24>: xor %eax,%eax
0x0000000000400596 <+26>: mov $0x4006ac,%edi
0x000000000040059b <+31>: callq 0x400440 <puts@plt>
0x00000000004005a0 <+36>: mov -0x8(%rbp),%rax
0x00000000004005a4 <+40>: xor %fs:0x28,%rax
0x00000000004005ad <+49>: je 0x4005b4 <foo+56>
0x00000000004005af <+51>: callq 0x400450 <__stack_chk_fail@plt>
0x00000000004005b4 <+56>: leaveq
0x00000000004005b5 <+57>: retq
What is the meaning of this kind of syntax?
FSis a segment register, so this syntax means an offset inside the segment pointed to byFS. There's no syntax for extracting bits from a register (x86 ISA does not support operands like that). 0x28(%fs) would mean value ofFSplus 0x28 which is a different thing. – Igor Skochinsky May 03 '13 at 08:49fsand friends are usually referred to as selectors in flat address mode, since they don't quite have the same meaning as they used to in real mode. – 0xC0000022L May 03 '13 at 11:10