-
Problem report
-
Resolution: Fixed
-
Trivial
-
7.2.0alpha1
-
None
-
S24-W36/37
-
1
Zabbix Agent's Go implementation requires thread-local storage.
TLS was standardized in ISO/IEC 9899:1999 (aka C99), but leaves many of the details of how that storage is provided to be implementation defined. There are two methods in practice. In the case of GCC, the TLBs (thread-local storage blocks) are allocated by the compiler itself in the .bss segment. Others, most notably Clang, expect the loader to create the TLB space, and then perform the relocations as necessary.
We perform a configure-time test for this, although only until the compile stage (which only tells us if the compiler recognizes the __thread keyword), and define a preprocessor macro HAVE_THREAD_LOCAL to indicate this. We only require this capability when building the Go agent.
During ZBX-8236 (6e5aae1e), as part of a fix for leaking memory upon thread termination on Windows, a conditional definition of ZBX_THREAD_LOCAL was introduced in the zbxtypes.h header.
During ZBX-16998 (88332506) the block was updated to add a guard that prevented processing the block when the macro ZBX_BUILD_AGENT2 was undefined.
During ZBXNEXT-8166 (190d4fe8c6), this guard was dropped.
Because the header is processed during all C code compilation, in cases where the compiler doesn't support the keyword at all (gcc3 is such a case), the entire compilation fails when the header is processed, even in cases when we're not asking to build the Go agent.
The entire block shouldn't be in that header to begin with; and even if we want to keep it, it shouldn't be issuing an (#error) directive in any case. The Go agent can perform the test in a CGO fragment, if it really needs to, and if we want to keep these conditional ZBX_THREAD_LOCAL definitions, should be moved to the header for the library dealing with threads.