Skip to content

Commit 69f3244

Browse files
authored
[NFC][sanitizer] Switch to gnu_get_libc_version (llvm#108724)
`gnu_get_libc_version` unlike `confstr` is not intercepted. We should be able to use this function earier. Looks like we use `confstr` staring from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60038 but there is no specific reason to refer it over `gnu_get_libc_version`.
1 parent bc54e56 commit 69f3244

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+
# ifdef 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+
# ifdef 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)