Skip to content

Commit 35cec80

Browse files
authored
[lldb][test] Workaround older systems that lack gettid (#104831)
Older glibc versions do not provide `gettid`. Provide our own `gettid` in these cases. Fixes a build failure caused by #104109.
1 parent 0f22d47 commit 35cec80

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
@@ -24,6 +24,11 @@
2424
#include <sys/resource.h>
2525
#include <unistd.h>
2626

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

2934
namespace {

0 commit comments

Comments
 (0)