From a74215866755cac849a8c626e77e2ae7fd411d95 Mon Sep 17 00:00:00 2001 From: Adrian Ratiu Date: Mon, 1 Mar 2021 20:04:37 +0200 Subject: [PATCH] threads.h: avoid defining gettid on glibc >= 2.32 Glibc >=2.32 exposes a gettid() which clashes with libcutils thread.h, so add a check to not expose it if building against newer glibc (ChromiumOS will still use glibc 2.27 besides 2.32). Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1182060 Test: Builds without errors on both glibc 2.32 and 2.27. Change-Id: Ib71fa1bc9fa185e3668002407dbed05a80c87740 --- libcutils/include/cutils/threads.h | 2 ++ libcutils/threads.cpp | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libcutils/include/cutils/threads.h b/libcutils/include/cutils/threads.h index 0f7f8a8c1..0082c6c63 100644 --- a/libcutils/include/cutils/threads.h +++ b/libcutils/include/cutils/threads.h @@ -31,7 +31,9 @@ extern "C" { // // Deprecated: use android::base::GetThreadId instead, which doesn't truncate on Mac/Windows. // +#if !defined(__GLIBC__) || __GLIBC__ >= 2 && __GLIBC_MINOR__ < 32 extern pid_t gettid(); +#endif #ifdef __cplusplus } diff --git a/libcutils/threads.cpp b/libcutils/threads.cpp index 8cfee1e53..6ece7a3af 100644 --- a/libcutils/threads.cpp +++ b/libcutils/threads.cpp @@ -25,8 +25,9 @@ #include #endif -#if defined(__BIONIC__) +#if defined(__BIONIC__) || defined(__GLIBC__) && __GLIBC_MINOR__ >= 32 // No definition needed for Android because we'll just pick up bionic's copy. +// No definition needed for Glibc >= 2.32 because it exposes its own copy. #else pid_t gettid() { #if defined(__APPLE__)