Open Source & Linux Lab

It's better when it's simple

User Tools

Site Tools


etc:users:jcmvbkbc:binutils-xtensa

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
etc:users:jcmvbkbc:binutils-xtensa [2024/01/19 16:04] – status update jcmvbkbcetc:users:jcmvbkbc:binutils-xtensa [2024/03/18 14:47] (current) jcmvbkbc
Line 1: Line 1:
-===== binutils support for Xtensa =====+====== binutils support for Xtensa ======
  
   * git tree: https://github.com/jcmvbkbc/binutils-gdb-xtensa   * git tree: https://github.com/jcmvbkbc/binutils-gdb-xtensa
  
-==== FDPIC support ====+===== FDPIC support =====
  
   * [+] static linking   * [+] static linking
   * [+] PDE   * [+] PDE
   * [+] PIE   * [+] PIE
-  * [-] PLT and lazy binding +  * [±] PLT and lazy binding 
-  * [-] TLS+  * [+] TLS
  
-==== FDPIC instruction sequences ====+===== FDPIC instruction sequences =====
  
-=== Local call ====+==== Local call ====
  
 Default local call Default local call
Line 42: Line 42:
 <code> <code>
         call0.l target, tmp1, tmp2, localGOTptr         call0.l target, tmp1, tmp2, localGOTptr
 +</code>
 +
 +==== PLT call ====
 +
 +Obvious version:
 +<code>
 ++0:     movi    tmp, target@PLTGOT
 ++3:     add     tmp, tmp, localGOTptr
 ++5:     l32i    tmp, tmp, 0
 ++7:     l32i    GOTptr, tmp, 4
 ++9:     l32i    tmp, tmp, 0
 ++11:    callx0  tmp
 +</code>
 +<code>
 +target@PLT:
 ++0:     movi    a8, target@PLTGOT
 ++3:     add     a8, a8, GOTptr
 ++5:     movi    a9, target-symbol
 ++8:     l32i    a10, GOTptr, RESOLVER_FN
 ++10:    l32i    GOTptr, GOTptr, RESOLVER_GOT
 ++12:    jx0     a10
 +</code>
 +
 +The inline part calls the PLT part only once, after resolution the inline part calls the target directly.
 +The adjustment is done to a single GOT entry, so it's atomic.
 +The inline part can be reduced to a fixed direct call to the PLT:
 +<code>
 ++0:     mov     GOTptr, localGOTptr
 ++2:     call0   target@PLT
 +</code>
 +that reduces the inline part from 14 to 5 bytes, but adds two jumps to each call and some special logic to the resolver to avoid name resolution on each call.
 +
 +==== TLS Support ====
 +
 +=== TLS General Dynamic ===
 +
 +<code>
 ++0:     movi    tmp1, x@GOTTLSDESC
 ++3:     add     arg0, tmp1, localGOTptr         # TLS_ARG
 ++5:     l32i    tmp2, arg0, 0                   # TLS_FUNCDESC
 ++7:     l32i    GOTptr, tmp2, 4                 # TLS_GOT
 ++9:     _l32i   tmp3, tmp2, 0                   # TLS_FUNC
 ++12:    callx0  tmp3                            # TLS_CALL
 +</code>
 +
 +This TLSDESC is not the same as the descriptor of the default xtensa toolchain. It contains two pointers, one to the resolver function, the other to that other descriptor containing DTPOFF and module index in the dtv.
 +
 +=== TLS Local Dynamic ===
 +
 +Header getting the address of the _TLS_MODULE_BASE_ is the same as in General Dynamic, or a possible one instruction less version:
 +<code>
 ++0:     l32i    arg0, localGOTptr, _TLS_MODULE_BASE_DESC_OFF
 ++2:     l32i    tmp1, arg0, 0
 ++4:     l32i    GOTptr, tmp1, 4
 ++6:     _l32i   tmp2, tmp1, 0
 ++9:     callx0  tmp2
 +...
 ++m:     movi    tmp3, x@DTPOFF
 ++m+3:   add     res, tmp3, rv0
 +...
 +</code>
 +_TLS_MODULE_BASE_DESC_OFF is a small fixed offset (16?) from the GOT base where an entry with R_XTENSA_TLSDESC(_TLS_MODULE_BASE_) relocation against it is placed.
 +
 +=== TLS Initial Exec ===
 +
 +<code>
 ++0:     movi    tmp1, x@GOTTPOFF
 ++3:     add     tmp2, tmp1, localGOTptr         # TLS_TPOFF_PTR
 ++5:     l32i    tmp3, tmp2, 0                   # TLS_TPOFF_LOAD
 ++7:     rur     tmp4, THREADPTR
 ++10:    add     res, tmp3, tmp4
 +</code>
 +
 +=== TLS Local Exec ===
 +
 +<code>
 ++0:     movi    tmp1, x@TPOFF
 ++3:     rur     tmp2, THREADPTR
 ++6:     add     res, tmp1, tmp2
 +</code>
 +
 +==== Linker optimizations ====
 +
 +=== General Dynamic -> Initial Exec ===
 +
 +<code>
 ++0:     movi    tmp1, x@GOTTLSDESC                                              movi    tmp1, x@GOTTPOFF
 ++3:     add     arg0, tmp1, localGOTptr         # TLS_ARG                       add     arg0, tmp1, localGOTptr
 ++5:     l32i    tmp2, arg0, 0                   # TLS_FUNCDESC                  l32i    arg0, arg0, 0
 ++7:     l32i    GOTptr, tmp2, 4                 # TLS_GOT                       nop
 ++9:     _l32i   tmp3, tmp2, 0                   # TLS_FUNC                      rur     tmp3, THREADPTR
 ++12:    callx0  tmp3                            # TLS_CALL                      add     arg0, arg0, tmp3
 +</code>
 +
 +=== General Dynamic -> Local Exec ===
 +
 +<code>
 ++0:     movi    tmp1, x@GOTTLSDESC                                              movi    tmp1, x@TPOFF
 ++3:     add     arg0, tmp1, localGOTptr         # TLS_ARG                       mov     arg0, tmp1
 ++5:     l32i    tmp2, arg0, 0                   # TLS_FUNCDESC                  nop
 ++7:     l32i    GOTptr, tmp2, 4                 # TLS_GOT                       nop
 ++9:     _l32i   tmp3, tmp2, 0                   # TLS_FUNC                      rur     tmp3, THREADPTR
 ++12:    callx0  tmp3                            # TLS_CALL                      add     arg0, arg0, tmp3
 +</code>
 +
 +=== Initial Exec -> Local Exec ===
 +
 +<code>
 ++0:     movi    tmp1, x@GOTTPOFF                                                movi    tmp1, x@TPOFF
 ++3:     add     tmp2, tmp1, localGOTptr         # TLS_TPOFF_PTR                 mov     tmp2, tmp1
 ++5:     l32i    tmp3, tmp2, 0                   # TLS_TPOFF_LOAD                mov     tmp3, tmp2
 ++7:     rur     tmp4, THREADPTR                                                 rur     tmp4, THREADPTR
 ++10:    add     res, tmp3, tmp4                                                 add     res, tmp3, tmp4
 </code> </code>
  
etc/users/jcmvbkbc/binutils-xtensa.1705669460.txt.gz · Last modified: 2024/01/19 16:04 by jcmvbkbc