-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[NFC][sanitizer] Switch to gnu_get_libc_version
#108724
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[NFC][sanitizer] Switch to gnu_get_libc_version
#108724
Conversation
Created using spr 1.3.4 [skip ci]
Created using spr 1.3.4
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Vitaly Buka (vitalybuka) Changes
Looks like we use Full diff: https://github.com/llvm/llvm-project/pull/108724.diff 1 Files Affected:
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
index 071ecc4516e0f0..bc3a41bba03fc1 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>
+# ifdef 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;
+# ifdef SANITIZER_GLIBC
+ const char *p = gnu_get_libc_version();
*major = internal_simple_strtoll(p, &p, 10);
+ // Caller do 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;
|
The header gnu/libc-version.h has been in glibc available since 1998. Nice! |
Created using spr 1.3.4 [skip ci]
This reverts commit 69f3244. Reason: buildbot breakage because Android doesn't have <gnu/libc-version.h> https://lab.llvm.org/buildbot/#/builders/186/builds/2381 (It's probably easy to fix but I don't readily have an Android device to test.)
…)" (llvm#108885) In llvm#108724 `#ifdef` was used instead of `#if`. This reverts commit 68e4518.
gnu_get_libc_version
unlikeconfstr
is notintercepted. We should be able to use this
function earier.
Looks like we use
confstr
staring fromhttps://gcc.gnu.org/bugzilla/show_bug.cgi?id=60038
but there is no specific reason to refer it over
gnu_get_libc_version
.