Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 3437a82

Browse files
authored
Enable build on old Linux (#11414)
This change enables building coreclr on old Linux distros that don't have PR_SET_PTRACER and don't have _xstate struct in the standard sigcontext.h header.
1 parent eac27ca commit 3437a82

File tree

6 files changed

+36
-5
lines changed

6 files changed

+36
-5
lines changed

src/debug/createdump/threadinfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ThreadInfo::Initialize(ICLRDataTarget* dataTarget)
3838
return false;
3939
}
4040
}
41-
TRACE("Thread %04x RIP %016llx RSP %016llx\n", m_tid, m_gpRegisters.rip, m_gpRegisters.rsp);
41+
TRACE("Thread %04x RIP %016llx RSP %016llx\n", m_tid, (unsigned long long)m_gpRegisters.rip, (unsigned long long)m_gpRegisters.rsp);
4242
return true;
4343
}
4444

src/pal/src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ elseif(PAL_CMAKE_PLATFORM_ARCH_I386)
9393
set(PAL_ARCH_SOURCES_DIR i386)
9494
endif()
9595

96-
if(CMAKE_SYSTEM_NAME STREQUAL Linux AND NOT CLR_CMAKE_PLATFORM_ALPINE_LINUX)
96+
if(PAL_CMAKE_PLATFORM_ARCH_AMD64 AND CMAKE_SYSTEM_NAME STREQUAL Linux AND NOT CLR_CMAKE_PLATFORM_ALPINE_LINUX)
9797
# Currently the _xstate is not available on Alpine Linux
9898
add_definitions(-DXSTATE_SUPPORTED)
99-
endif(CMAKE_SYSTEM_NAME STREQUAL Linux AND NOT CLR_CMAKE_PLATFORM_ALPINE_LINUX)
99+
endif(PAL_CMAKE_PLATFORM_ARCH_AMD64 AND CMAKE_SYSTEM_NAME STREQUAL Linux AND NOT CLR_CMAKE_PLATFORM_ALPINE_LINUX)
100100

101101
if(CLR_CMAKE_PLATFORM_ALPINE_LINUX)
102102
# Setting RLIMIT_NOFILE breaks debugging of coreclr on Alpine Linux for some reason

src/pal/src/config.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
#cmakedefine HAVE_UNW_GET_ACCESSORS
6767
#cmakedefine01 HAVE_XSWDEV
6868
#cmakedefine01 HAVE_XSW_USAGE
69+
#cmakedefine01 HAVE_PUBLIC_XSTATE_STRUCT
70+
#cmakedefine01 HAVE_PR_SET_PTRACER
6971

7072
#cmakedefine01 HAVE_STAT_TIMESPEC
7173
#cmakedefine01 HAVE_STAT_NSEC

src/pal/src/configure.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,25 @@ int main(int argc, char **argv)
10221022
return 0;
10231023
}" HAVE_XSW_USAGE)
10241024

1025+
check_cxx_source_compiles("
1026+
#include <signal.h>
1027+
1028+
int main(int argc, char **argv)
1029+
{
1030+
struct _xstate xstate;
1031+
struct _fpx_sw_bytes bytes;
1032+
return 0;
1033+
}" HAVE_PUBLIC_XSTATE_STRUCT)
1034+
1035+
check_cxx_source_compiles("
1036+
#include <sys/prctl.h>
1037+
1038+
int main(int argc, char **argv)
1039+
{
1040+
int flag = (int)PR_SET_PTRACER;
1041+
return 0;
1042+
}" HAVE_PR_SET_PTRACER)
1043+
10251044
set(CMAKE_REQUIRED_LIBRARIES pthread)
10261045
check_cxx_source_compiles("
10271046
#include <errno.h>

src/pal/src/include/pal/context.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ typedef ucontext_t native_context_t;
3939
#else // HAVE_UCONTEXT_T
4040
#error Native context type is not known on this platform!
4141
#endif // HAVE_UCONTEXT_T
42+
43+
#if defined(XSTATE_SUPPORTED) && !HAVE_PUBLIC_XSTATE_STRUCT
44+
namespace asm_sigcontext
45+
{
46+
#include <asm/sigcontext.h>
47+
};
48+
using asm_sigcontext::_fpx_sw_bytes;
49+
using asm_sigcontext::_xstate;
50+
#endif // defined(XSTATE_SUPPORTED) && !HAVE_PUBLIC_XSTATE_STRUCT
51+
4252
#else // !HAVE_MACH_EXCEPTIONS
4353
#include <mach/kern_return.h>
4454
#include <mach/mach_port.h>

src/pal/src/thread/process.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2981,7 +2981,7 @@ PROCAbort()
29812981
// Do any shutdown cleanup before aborting or creating a core dump
29822982
PROCNotifyProcessShutdown();
29832983

2984-
#if HAVE_PRCTL_H
2984+
#if HAVE_PRCTL_H && HAVE_PR_SET_PTRACER
29852985
// If enabled, launch the create minidump utility and wait until it completes
29862986
if (g_argvCreateDump[0] != nullptr)
29872987
{
@@ -3018,7 +3018,7 @@ PROCAbort()
30183018
}
30193019
}
30203020
}
3021-
#endif // HAVE_PRCTL_H
3021+
#endif // HAVE_PRCTL_H && HAVE_PR_SET_PTRACER
30223022
// Abort the process after waiting for the core dump to complete
30233023
abort();
30243024
}

0 commit comments

Comments
 (0)