Skip to content

Commit 74f41e9

Browse files
vitalybukatmsri
authored andcommitted
[NFC][sanitizer] Move InitTlsSize (llvm#108922)
Move after ThreadDescriptorSizeFallback to be able to use it.
1 parent e573eb4 commit 74f41e9

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ bool SetEnv(const char *name, const char *value) {
209209
__attribute__((unused)) static int g_use_dlpi_tls_data;
210210

211211
# if SANITIZER_GLIBC && !SANITIZER_GO
212-
213212
static void GetGLibcVersion(int *major, int *minor, int *patch) {
214213
const char *p = gnu_get_libc_version();
215214
*major = internal_simple_strtoll(p, &p, 10);
@@ -218,26 +217,6 @@ static void GetGLibcVersion(int *major, int *minor, int *patch) {
218217
*minor = (*p == '.') ? internal_simple_strtoll(p + 1, &p, 10) : 0;
219218
*patch = (*p == '.') ? internal_simple_strtoll(p + 1, &p, 10) : 0;
220219
}
221-
222-
__attribute__((unused)) static size_t g_tls_size;
223-
224-
void InitTlsSize() {
225-
int major, minor, patch;
226-
GetGLibcVersion(&major, &minor, &patch);
227-
g_use_dlpi_tls_data = major == 2 && minor >= 25;
228-
229-
# if defined(__aarch64__) || defined(__x86_64__) || \
230-
defined(__powerpc64__) || defined(__loongarch__)
231-
auto *get_tls_static_info = (void (*)(size_t *, size_t *))dlsym(
232-
RTLD_DEFAULT, "_dl_get_tls_static_info");
233-
size_t tls_align;
234-
// Can be null if static link.
235-
if (get_tls_static_info)
236-
get_tls_static_info(&g_tls_size, &tls_align);
237-
# endif
238-
}
239-
# else
240-
void InitTlsSize() {}
241220
# endif // SANITIZER_GLIBC && !SANITIZER_GO
242221

243222
// On glibc x86_64, ThreadDescriptorSize() needs to be precise due to the usage
@@ -341,6 +320,28 @@ uptr ThreadDescriptorSize() {
341320
return val;
342321
}
343322

323+
# if SANITIZER_GLIBC
324+
__attribute__((unused)) static size_t g_tls_size;
325+
# endif
326+
327+
void InitTlsSize() {
328+
# if SANITIZER_GLIBC
329+
int major, minor, patch;
330+
GetGLibcVersion(&major, &minor, &patch);
331+
g_use_dlpi_tls_data = major == 2 && minor >= 25;
332+
333+
# if defined(__aarch64__) || defined(__x86_64__) || \
334+
defined(__powerpc64__) || defined(__loongarch__)
335+
auto *get_tls_static_info = (void (*)(size_t *, size_t *))dlsym(
336+
RTLD_DEFAULT, "_dl_get_tls_static_info");
337+
size_t tls_align;
338+
// Can be null if static link.
339+
if (get_tls_static_info)
340+
get_tls_static_info(&g_tls_size, &tls_align);
341+
# endif
342+
# endif // SANITIZER_GLIBC
343+
}
344+
344345
# if defined(__mips__) || defined(__powerpc64__) || SANITIZER_RISCV64 || \
345346
SANITIZER_LOONGARCH64
346347
// TlsPreTcbSize includes size of struct pthread_descr and size of tcb
@@ -361,8 +362,9 @@ static uptr TlsPreTcbSize() {
361362
return kTlsPreTcbSize;
362363
}
363364
# endif
364-
365-
# endif
365+
# else // (SANITIZER_FREEBSD || SANITIZER_GLIBC) && !SANITIZER_GO
366+
void InitTlsSize() {}
367+
# endif // (SANITIZER_FREEBSD || SANITIZER_GLIBC) && !SANITIZER_GO
366368

367369
# if (SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_SOLARIS) && \
368370
!SANITIZER_ANDROID && !SANITIZER_GO

0 commit comments

Comments
 (0)