How to interpret segment register accesses on x86-64?

前端 未结 2 631
春和景丽
春和景丽 2021-01-02 11:10

With this function:

mov    1069833(%rip),%rax        # 0x2b5c1bf9ef90 <_fini+3250648>
add    %fs:0x0,%rax
retq

How do I interpret the

2条回答
  •  抹茶落季
    2021-01-02 11:34

    This code:

    mov    1069833(%rip),%rax        # 0x2b5c1bf9ef90 <_fini+3250648>
    add    %fs:0x0,%rax
    retq
    

    is returning the address of a thread-local variable. %fs:0x0 is the address of the TCB (Thread Control Block), and 1069833(%rip) is the offset from there to the variable, which is known since the variable resides either in the program or on some dynamic library loaded at program's load time (libraries loaded at runtime via dlopen() need some different code).

    This is explained in great detail in Ulrich Drepper's TLS document, specially §4.3 and §4.3.6.

提交回复
热议问题