[Lldb-commits] [lldb] WIP: [lldb][test] Workaround older systems that lack gettid (PR #104831)

Will Hawkins via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 20 15:16:15 PDT 2024


https://github.com/hawkinsw updated https://github.com/llvm/llvm-project/pull/104831

>From 93949029c808e2e5991df2f3c498dcd008367c34 Mon Sep 17 00:00:00 2001
From: Will Hawkins <hawkinsw at obs.cr>
Date: Mon, 19 Aug 2024 14:43:45 -0400
Subject: [PATCH] [lldb][test] Workaround older systems that lack gettid

Older glibc versions do not have `gettid`. Provide our own `gettid` in these
cases.

Fixes a build failure caused by #104109.
---
 lldb/unittests/Process/elf-core/CMakeLists.txt        | 11 +++++++++++
 lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp |  5 +++++
 2 files changed, 16 insertions(+)

diff --git a/lldb/unittests/Process/elf-core/CMakeLists.txt b/lldb/unittests/Process/elf-core/CMakeLists.txt
index b852a3ffb863c1..68ab6e0683c182 100644
--- a/lldb/unittests/Process/elf-core/CMakeLists.txt
+++ b/lldb/unittests/Process/elf-core/CMakeLists.txt
@@ -1,3 +1,6 @@
+include(CheckSymbolExists)
+include(CMakePushCheckState)
+
 add_lldb_unittest(ProcessElfCoreTests
   ThreadElfCoreTest.cpp
 
@@ -13,3 +16,11 @@ add_lldb_unittest(ProcessElfCoreTests
   LINK_COMPONENTS
     Support
   )
+
+cmake_push_check_state()
+set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
+check_symbol_exists(gettid "unistd.h" HAVE_GETTID)
+if(HAVE_GETTID)
+  target_compile_definitions(ProcessElfCoreTests PRIVATE HAVE_GETTID)
+endif()
+cmake_pop_check_state()
diff --git a/lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp b/lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp
index ce146f62b0d826..c9879f5d94d538 100644
--- a/lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp
+++ b/lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp
@@ -23,6 +23,11 @@
 #include <mutex>
 #include <unistd.h>
 
+#ifndef HAVE_GETTID
+#include <sys/syscall.h>
+pid_t gettid() { return ((pid_t)syscall(SYS_gettid)); }
+#endif
+
 using namespace lldb_private;
 
 namespace {



More information about the lldb-commits mailing list