From ef97630fd20d24ee508c8287a3d7d8699a59fbaa Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Fri, 27 Jan 2017 12:23:51 +0000 Subject: [PATCH] Refactor the android accept hack This moves the accept hack from the android toolchain file into LLDBConfig.cmake. This allows successful lldb android compilation without relying on our custom toolchain file. llvm-svn: 293281 --- lldb/cmake/modules/LLDBConfig.cmake | 4 ++++ lldb/cmake/platforms/Android.cmake | 8 -------- lldb/source/Host/common/Socket.cpp | 12 +++++++----- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake index 26f9c93902a4..0ee60a705afb 100644 --- a/lldb/cmake/modules/LLDBConfig.cmake +++ b/lldb/cmake/modules/LLDBConfig.cmake @@ -412,4 +412,8 @@ if(LLDB_USE_BUILTIN_DEMANGLER) add_definitions(-DLLDB_USE_BUILTIN_DEMANGLER) endif() +if ((CMAKE_SYSTEM_NAME MATCHES "Android") AND LLVM_BUILD_STATIC) + add_definitions(-DANDROID_BUILD_STATIC) +endif() + find_package(Backtrace) diff --git a/lldb/cmake/platforms/Android.cmake b/lldb/cmake/platforms/Android.cmake index d3e9a05f915e..789322f4353c 100644 --- a/lldb/cmake/platforms/Android.cmake +++ b/lldb/cmake/platforms/Android.cmake @@ -102,10 +102,6 @@ elseif( ANDROID_ABI STREQUAL "armeabi" ) # 64 bit atomic operations used in c++ libraries require armv7-a instructions # armv5te and armv6 were tried but do not work. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv7-a -mthumb" ) - if( LLVM_BUILD_STATIC ) - # Temporary workaround for static linking with the latest API. - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -DANDROID_ARM_BUILD_STATIC" ) - endif() elseif( ANDROID_ABI STREQUAL "mips" ) # http://b.android.com/182094 list( FIND LLDB_SYSTEM_LIBS atomic index ) @@ -113,10 +109,6 @@ elseif( ANDROID_ABI STREQUAL "mips" ) list( APPEND LLDB_SYSTEM_LIBS atomic ) set( LLDB_SYSTEM_LIBS ${LLDB_SYSTEM_LIBS} CACHE INTERNAL "" FORCE ) endif() - if( LLVM_BUILD_STATIC ) - # Temporary workaround for static linking with the latest API. - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -DANDROID_MIPS_BUILD_STATIC" ) - endif() endif() # Use gold linker and enable safe ICF in case of x86, x86_64 and arm diff --git a/lldb/source/Host/common/Socket.cpp b/lldb/source/Host/common/Socket.cpp index 79777c88fa46..8082fff179f1 100644 --- a/lldb/source/Host/common/Socket.cpp +++ b/lldb/source/Host/common/Socket.cpp @@ -38,11 +38,9 @@ #include #include #include -#if defined(ANDROID_ARM_BUILD_STATIC) || defined(ANDROID_MIPS_BUILD_STATIC) #include #include #include -#endif // ANDROID_ARM_BUILD_STATIC || ANDROID_MIPS_BUILD_STATIC #endif // __ANDROID__ using namespace lldb; @@ -424,9 +422,13 @@ NativeSocket Socket::AcceptSocket(NativeSocket sockfd, struct sockaddr *addr, socklen_t *addrlen, bool child_processes_inherit, Error &error) { error.Clear(); -#if defined(ANDROID_ARM_BUILD_STATIC) || defined(ANDROID_MIPS_BUILD_STATIC) - // Temporary workaround for statically linking Android lldb-server with the - // latest API. +#if defined(ANDROID_BUILD_STATIC) + // Hack: + // This enables static linking lldb-server to an API 21 libc, but still having + // it run on older devices. It is necessary because API 21 libc's + // implementation of accept() uses the accept4 syscall(), which is not + // available in older kernels. Using an older libc would fix this issue, but + // introduce other ones, as the old libraries were quite buggy. int fd = syscall(__NR_accept, sockfd, addr, addrlen); if (fd >= 0 && !child_processes_inherit) { int flags = ::fcntl(fd, F_GETFD);