Index: tools/lldb/include/lldb/Host/linux/Signalfd.h =================================================================== --- tools/lldb/include/lldb/Host/linux/Signalfd.h +++ tools/lldb/include/lldb/Host/linux/Signalfd.h @@ -12,14 +12,21 @@ #ifndef liblldb_Host_linux_Signalfd_h_ #define liblldb_Host_linux_Signalfd_h_ +#include + #ifdef __ANDROID_NDK__ #include #endif -#if defined(__ANDROID_API__) && __ANDROID_API__ < 21 +#if (defined(__ANDROID_API__) && __ANDROID_API__ < 21) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)) #include + +#if defined(__ANDROID_API__) && __ANDROID_API__ < 21 #include +#else +#include +#endif #define SFD_CLOEXEC O_CLOEXEC #define SFD_NONBLOCK O_NONBLOCK Index: tools/lldb/source/Host/common/File.cpp =================================================================== --- tools/lldb/source/Host/common/File.cpp +++ tools/lldb/source/Host/common/File.cpp @@ -20,6 +20,7 @@ #include "lldb/Host/windows/windows.h" #else #include +#include #endif #include "llvm/Support/Process.h" // for llvm::sys::Process::FileDescriptorHasColors() @@ -296,8 +297,11 @@ #ifndef _WIN32 if (options & eOpenOptionNonBlocking) oflag |= O_NONBLOCK; + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23) if (options & eOpenOptionCloseOnExec) oflag |= O_CLOEXEC; +#endif #else oflag |= O_BINARY; #endif @@ -325,6 +329,15 @@ error.SetErrorToErrno(); else { +#ifndef _WIN32 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) + if (options & eOpenOptionCloseOnExec) + { + int oldFlags = fcntl(m_descriptor, F_GETFD, 0); + fcntl(m_descriptor, F_SETFD, FD_CLOEXEC|oldFlags); + } +#endif +#endif m_should_close_fd = true; m_options = options; } Index: tools/lldb/source/Host/linux/HostThreadLinux.cpp =================================================================== --- tools/lldb/source/Host/linux/HostThreadLinux.cpp +++ tools/lldb/source/Host/linux/HostThreadLinux.cpp @@ -30,7 +30,7 @@ void HostThreadLinux::SetName(lldb::thread_t thread, llvm::StringRef name) { -#if (defined(__GLIBC__) && defined(_GNU_SOURCE)) || defined(__ANDROID__) +#if (defined(__GLIBC__) && defined(_GNU_SOURCE) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 12) || defined(__ANDROID__) ::pthread_setname_np(thread, name.data()); #else (void) thread; Index: tools/lldb/source/Host/posix/PipePosix.cpp =================================================================== --- tools/lldb/source/Host/posix/PipePosix.cpp +++ tools/lldb/source/Host/posix/PipePosix.cpp @@ -29,6 +29,8 @@ #include #include +#include + using namespace lldb; using namespace lldb_private; @@ -38,7 +40,7 @@ // pipe2 is supported by a limited set of platforms // TODO: Add more platforms that support pipe2. -#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD__ >= 10) || defined(__NetBSD__) +#if (defined(__linux__) && LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)) || (defined(__FreeBSD__) && __FreeBSD__ >= 10) || defined(__NetBSD__) #define PIPE2_SUPPORTED 1 #else #define PIPE2_SUPPORTED 0 @@ -248,13 +250,25 @@ return Error("Pipe is already opened"); int flags = O_RDONLY | O_NONBLOCK; + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23) if (!child_process_inherit) flags |= O_CLOEXEC; +#endif Error error; int fd = ::open(name.data(), flags); if (fd != -1) + { +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) + if (!child_process_inherit) + { + int oldFlags = fcntl(fd, F_GETFD, 0); + fcntl(fd, F_SETFD, FD_CLOEXEC|oldFlags); + } +#endif m_fds[READ] = fd; + } else error.SetErrorToErrno(); @@ -268,8 +282,11 @@ return Error("Pipe is already opened"); int flags = O_WRONLY | O_NONBLOCK; + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23) if (!child_process_inherit) flags |= O_CLOEXEC; +#endif using namespace std::chrono; const auto finish_time = Now() + timeout; @@ -296,6 +313,13 @@ } else { +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) + if (!child_process_inherit) + { + int oldFlags = fcntl(fd, F_GETFD, 0); + fcntl(fd, F_SETFD, FD_CLOEXEC|oldFlags); + } +#endif m_fds[WRITE] = fd; } } Index: tools/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp =================================================================== --- tools/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ tools/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -69,6 +69,36 @@ #define TRAP_HWBKPT 4 #endif +// Missing defines due to bug: https://sourceware.org/bugzilla/show_bug.cgi?id=4125 + +#if !HAVE_DECL_ADDR_NO_RANDOMIZE + #define ADDR_NO_RANDOMIZE 0x0040000 +#endif + +#ifndef PTRACE_O_TRACECLONE + #define PTRACE_O_TRACECLONE 0x00000008 +#endif + +#ifndef PTRACE_O_TRACEEXEC + #define PTRACE_O_TRACEEXEC 0x00000010 +#endif + +#ifndef PTRACE_O_TRACEEXIT + #define PTRACE_O_TRACEEXIT 0x00000040 +#endif + +#ifndef PTRACE_EVENT_CLONE + #define PTRACE_EVENT_CLONE 3 +#endif + +#ifndef PTRACE_EVENT_EXEC + #define PTRACE_EVENT_EXEC 4 +#endif + +#ifndef PTRACE_EVENT_EXIT + #define PTRACE_EVENT_EXIT 6 +#endif + using namespace lldb; using namespace lldb_private; using namespace lldb_private::process_linux; Index: tools/lldb/source/Target/ProcessLaunchInfo.cpp =================================================================== --- tools/lldb/source/Target/ProcessLaunchInfo.cpp +++ tools/lldb/source/Target/ProcessLaunchInfo.cpp @@ -18,6 +18,8 @@ #if !defined(_WIN32) #include + +#include #endif using namespace lldb; @@ -360,7 +362,7 @@ __FUNCTION__); int open_flags = O_RDWR | O_NOCTTY; -#if !defined(_MSC_VER) +#if !defined(_MSC_VER) && LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23) // We really shouldn't be specifying platform specific flags // that are intended for a system call in generic code. But // this will have to do for now. Index: tools/lldb/source/Utility/PseudoTerminal.cpp =================================================================== --- tools/lldb/source/Utility/PseudoTerminal.cpp +++ tools/lldb/source/Utility/PseudoTerminal.cpp @@ -32,6 +32,8 @@ pid_t fork(void) { return 0; } pid_t setsid(void) { return 0; } + +#include #elif defined(__ANDROID_NDK__) #include "lldb/Host/android/Android.h" int posix_openpt(int flags); @@ -242,7 +244,10 @@ pid_t pid = LLDB_INVALID_PROCESS_ID; #if !defined(LLDB_DISABLE_POSIX) int flags = O_RDWR; + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23) flags |= O_CLOEXEC; +#endif if (OpenFirstAvailableMaster (flags, error_str, error_len)) { // Successfully opened our master pseudo terminal