Skip to content

Commit c71a2b6

Browse files
vitalybukatmsri
authored andcommitted
Reapply "[NFC][sanitizer] Switch to gnu_get_libc_version (llvm#108724)" (llvm#108885)
In llvm#108724 `#ifdef` was used instead of `#if`. This reverts commit 68e4518.
1 parent 156ef0b commit c71a2b6

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
# include <sys/resource.h>
4141
# include <syslog.h>
4242

43+
# if SANITIZER_GLIBC
44+
# include <gnu/libc-version.h>
45+
# endif
46+
4347
# if !defined(ElfW)
4448
# define ElfW(type) Elf_##type
4549
# endif
@@ -198,17 +202,11 @@ bool SetEnv(const char *name, const char *value) {
198202

199203
__attribute__((unused)) static bool GetLibcVersion(int *major, int *minor,
200204
int *patch) {
201-
# ifdef _CS_GNU_LIBC_VERSION
202-
char buf[64];
203-
uptr len = confstr(_CS_GNU_LIBC_VERSION, buf, sizeof(buf));
204-
if (len >= sizeof(buf))
205-
return false;
206-
buf[len] = 0;
207-
static const char kGLibC[] = "glibc ";
208-
if (internal_strncmp(buf, kGLibC, sizeof(kGLibC) - 1) != 0)
209-
return false;
210-
const char *p = buf + sizeof(kGLibC) - 1;
205+
# if SANITIZER_GLIBC
206+
const char *p = gnu_get_libc_version();
211207
*major = internal_simple_strtoll(p, &p, 10);
208+
// Caller does not expect anything else.
209+
CHECK_EQ(*major, 2);
212210
*minor = (*p == '.') ? internal_simple_strtoll(p + 1, &p, 10) : 0;
213211
*patch = (*p == '.') ? internal_simple_strtoll(p + 1, &p, 10) : 0;
214212
return true;

0 commit comments

Comments
 (0)