Open itamar8910 opened 3 years ago
https://github.com/gunnarbeutner/serenity/tree/shlibs-tls has some initial work towards implementing -ftls-mode=global-dynamic
for shared libraries.
Also, yeah, we should move the main program's TLS data towards the end of the TLS block.
First use case is defining TLS variables as
static
.This code works:
A
R_386_TLS_TPOFF
relocation is generated, as expected (relevant code in the loader).However, if we also define
tls_var
asstatic
, then there is aR_386_TLS_TPOFF
without a value for the relocation's symbol:In this case we won't perform the relocation and access to this TLS variable will be incorrect.
@gunnarbeutner suggested switching from
-ftls-model=initial-exec
to-ftls-mode=global-dynamic
to fix this.Second use case is defining TLS variables in the main program (i.e not in a shared lib). Example:
When we do this, the TLS offset when accessing
a
is hardcoded to-4
:Our current implementation assumes that every access to TLS data first gets its offset from the GOT, which we set up when handling TLS relocations. It seems that the compiler assumes that we put the main program's TLS data at the end of the TLS block, so a possible fix would be to actually do that (Currently, we put the main program's TLS at the beginning of the TLS block).
also cc @ADKaster