Skip to content

Commit 9394902

Browse files
committed
[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.
1 parent 6e0fc15 commit 9394902

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lldb/unittests/Process/elf-core/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
include(CheckSymbolExists)
2+
include(CMakePushCheckState)
3+
14
add_lldb_unittest(ProcessElfCoreTests
25
ThreadElfCoreTest.cpp
36

@@ -13,3 +16,11 @@ add_lldb_unittest(ProcessElfCoreTests
1316
LINK_COMPONENTS
1417
Support
1518
)
19+
20+
cmake_push_check_state()
21+
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
22+
check_symbol_exists(gettid "unistd.h" HAVE_GETTID)
23+
if(HAVE_GETTID)
24+
target_compile_definitions(ProcessElfCoreTests PRIVATE HAVE_GETTID)
25+
endif()
26+
cmake_pop_check_state()

lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
#include <mutex>
2424
#include <unistd.h>
2525

26+
#ifndef HAVE_GETTID
27+
#include <sys/syscall.h>
28+
pid_t gettid() { return ((pid_t)syscall(SYS_gettid)); }
29+
#endif
30+
2631
using namespace lldb_private;
2732

2833
namespace {

0 commit comments

Comments
 (0)