[compiler-rt] Reapply "[NFC][sanitizer] Switch to `gnu_get_libc_version` (#108724)" (PR #108885)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 16 14:13:07 PDT 2024
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/108885
In #108724 `#ifdef` was used instead of `#if`.
This reverts commit 68e4518598d63efa02230f400e50263baccbb8e4.
>From 56e9e88b019839dcea9ae1ff5290d190a169fa0b Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Mon, 16 Sep 2024 14:12:51 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.4
---
.../sanitizer_linux_libcdep.cpp | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
index 51c1f9ff111de9..21bd2a23f5763c 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -40,6 +40,10 @@
# include <sys/resource.h>
# include <syslog.h>
+# if SANITIZER_GLIBC
+# include <gnu/libc-version.h>
+# endif
+
# if !defined(ElfW)
# define ElfW(type) Elf_##type
# endif
@@ -198,17 +202,11 @@ bool SetEnv(const char *name, const char *value) {
__attribute__((unused)) static bool GetLibcVersion(int *major, int *minor,
int *patch) {
-# ifdef _CS_GNU_LIBC_VERSION
- char buf[64];
- uptr len = confstr(_CS_GNU_LIBC_VERSION, buf, sizeof(buf));
- if (len >= sizeof(buf))
- return false;
- buf[len] = 0;
- static const char kGLibC[] = "glibc ";
- if (internal_strncmp(buf, kGLibC, sizeof(kGLibC) - 1) != 0)
- return false;
- const char *p = buf + sizeof(kGLibC) - 1;
+# if SANITIZER_GLIBC
+ const char *p = gnu_get_libc_version();
*major = internal_simple_strtoll(p, &p, 10);
+ // Caller does not expect anything else.
+ CHECK_EQ(*major, 2);
*minor = (*p == '.') ? internal_simple_strtoll(p + 1, &p, 10) : 0;
*patch = (*p == '.') ? internal_simple_strtoll(p + 1, &p, 10) : 0;
return true;
More information about the llvm-commits
mailing list