etc:users:jcmvbkbc:binutils-xtensa
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
etc:users:jcmvbkbc:binutils-xtensa [2023/09/09 02:21] – add toolchain building script jcmvbkbc | etc: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:// | * git tree: https:// | ||
- | ==== 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 ===== | ||
+ | |||
+ | ==== Local call ==== | ||
+ | |||
+ | Default local call | ||
+ | < | ||
+ | +0: | ||
+ | +3: | ||
+ | +5: | ||
+ | +7: | ||
+ | +9: | ||
+ | </ | ||
+ | |||
+ | No-GOT local call | ||
+ | < | ||
+ | +0: | ||
+ | +3: | ||
+ | +5: | ||
+ | +7: | ||
+ | +9: | ||
+ | </ | ||
+ | |||
+ | When call0 reaches the target it can be transformed to | ||
+ | < | ||
+ | +0: | ||
+ | +2: | ||
+ | </ | ||
+ | |||
+ | In the j.l style it could probably be done like | ||
+ | < | ||
+ | call0.l target, tmp1, tmp2, localGOTptr | ||
+ | </ | ||
+ | |||
+ | ==== PLT call ==== | ||
+ | |||
+ | Obvious version: | ||
+ | < | ||
+ | +0: | ||
+ | +3: | ||
+ | +5: | ||
+ | +7: | ||
+ | +9: | ||
+ | +11: callx0 | ||
+ | </ | ||
+ | < | ||
+ | target@PLT: | ||
+ | +0: | ||
+ | +3: | ||
+ | +5: | ||
+ | +8: | ||
+ | +10: l32i GOTptr, GOTptr, RESOLVER_GOT | ||
+ | +12: jx0 a10 | ||
+ | </ | ||
+ | |||
+ | 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: | ||
+ | < | ||
+ | +0: | ||
+ | +2: | ||
+ | </ | ||
+ | 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 === | ||
+ | |||
+ | < | ||
+ | +0: | ||
+ | +3: | ||
+ | +5: | ||
+ | +7: | ||
+ | +9: | ||
+ | +12: callx0 | ||
+ | </ | ||
+ | |||
+ | 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: | ||
+ | < | ||
+ | +0: | ||
+ | +2: | ||
+ | +4: | ||
+ | +6: | ||
+ | +9: | ||
+ | ... | ||
+ | +m: | ||
+ | +m+3: | ||
+ | ... | ||
+ | </ | ||
+ | _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 === | ||
+ | |||
+ | < | ||
+ | +0: | ||
+ | +3: | ||
+ | +5: | ||
+ | +7: | ||
+ | +10: add res, tmp3, tmp4 | ||
+ | </ | ||
+ | |||
+ | === TLS Local Exec === | ||
+ | |||
+ | < | ||
+ | +0: | ||
+ | +3: | ||
+ | +6: | ||
+ | </ | ||
+ | |||
+ | ==== Linker optimizations ==== | ||
+ | |||
+ | === General Dynamic -> Initial Exec === | ||
+ | |||
+ | < | ||
+ | +0: | ||
+ | +3: | ||
+ | +5: | ||
+ | +7: | ||
+ | +9: | ||
+ | +12: callx0 | ||
+ | </ | ||
+ | |||
+ | === General Dynamic -> Local Exec === | ||
+ | |||
+ | < | ||
+ | +0: | ||
+ | +3: | ||
+ | +5: | ||
+ | +7: | ||
+ | +9: | ||
+ | +12: callx0 | ||
+ | </ | ||
+ | |||
+ | === Initial Exec -> Local Exec === | ||
+ | |||
+ | < | ||
+ | +0: | ||
+ | +3: | ||
+ | +5: | ||
+ | +7: | ||
+ | +10: add res, tmp3, tmp4 | ||
+ | </ | ||
==== Manual toolchain building script ==== | ==== Manual toolchain building script ==== | ||
Line 44: | Line 190: | ||
" | " | ||
--target=$target \ | --target=$target \ | ||
+ | --with-sysroot=" | ||
--disable-shared --disable-werror --disable-gdb --disable-gdbstub \ | --disable-shared --disable-werror --disable-gdb --disable-gdbstub \ | ||
CFLAGS=" | CFLAGS=" |
etc/users/jcmvbkbc/binutils-xtensa.1694215289.txt.gz · Last modified: 2023/09/09 02:21 by jcmvbkbc