[PATCH] __ANDROID_NDK__ build

Andy Chien achien at blueshiftinc.com
Thu Oct 30 13:22:31 PDT 2014


apologies that was wrong version of the patch... new one attached...

On Thu, Oct 30, 2014 at 1:07 PM, Andy Chien <achien at blueshiftinc.com> wrote:

> Hi all,
>
> I'm working on Android build of LLDB using the Android NDK toolchain.
> Unfortunately there are enough subtle differences between using the NDK
> toolchain (for multiple targets) vs AOSP and building standalone LLVM vs
> building it as part of LLDB build process that I needed to add a new
> __ANDROID_NDK__ definition instead of relying on ANDROID or __ANDROID__.
>
> Please have a look. Thanks!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141030/d24124ad/attachment.html>
-------------- next part --------------
diff --git a/include/llvm/Target/TargetLibraryInfo.h b/include/llvm/Target/TargetLibraryInfo.h
index 56a8919..ebe6ff1 100644
--- a/include/llvm/Target/TargetLibraryInfo.h
+++ b/include/llvm/Target/TargetLibraryInfo.h
@@ -13,6 +13,12 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/Pass.h"
 
+#if defined(__ANDROID_NDK__)
+#undef stat64
+#undef lstat64
+#undef fstat64
+#endif
+
 namespace llvm {
   class Triple;
 
diff --git a/include/llvm/Transforms/Instrumentation.h b/include/llvm/Transforms/Instrumentation.h
index c6a339b..cd1643a 100644
--- a/include/llvm/Transforms/Instrumentation.h
+++ b/include/llvm/Transforms/Instrumentation.h
@@ -16,7 +16,7 @@
 
 #include "llvm/ADT/StringRef.h"
 
-#if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
+#if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID) && !defined(__ANDROID_NDK__)
 inline void *getDFSanArgTLSPtrForJIT() {
   extern __thread __attribute__((tls_model("initial-exec")))
     void *__dfsan_arg_tls;
@@ -78,7 +78,7 @@ ModulePass *createDataFlowSanitizerPass(StringRef ABIListFile = StringRef(),
                                         void *(*getArgTLS)() = nullptr,
                                         void *(*getRetValTLS)() = nullptr);
 
-#if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
+#if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID) && !defined(__ANDROID_NDK__)
 inline ModulePass *createDataFlowSanitizerPassForJIT(StringRef ABIListFile =
                                                          StringRef()) {
   return createDataFlowSanitizerPass(ABIListFile, getDFSanArgTLSPtrForJIT,
diff --git a/lib/Support/DynamicLibrary.cpp b/lib/Support/DynamicLibrary.cpp
index d2b551e..e0b0616 100644
--- a/lib/Support/DynamicLibrary.cpp
+++ b/lib/Support/DynamicLibrary.cpp
@@ -143,7 +143,7 @@ void* DynamicLibrary::SearchForAddressOfSymbol(const char *symbolName) {
 // On linux we have a weird situation. The stderr/out/in symbols are both
 // macros and global variables because of standards requirements. So, we
 // boldly use the EXPLICIT_SYMBOL macro without checking for a #define first.
-#if defined(__linux__) and !defined(__ANDROID__)
+#if defined(__linux__) and !defined(__ANDROID__) and !defined(__ANDROID_NDK__)
   {
     EXPLICIT_SYMBOL(stderr);
     EXPLICIT_SYMBOL(stdout);
diff --git a/lib/Support/LockFileManager.cpp b/lib/Support/LockFileManager.cpp
index 5b82c36..7132a15 100644
--- a/lib/Support/LockFileManager.cpp
+++ b/lib/Support/LockFileManager.cpp
@@ -58,7 +58,7 @@ LockFileManager::readLockFile(StringRef LockFileName) {
 }
 
 bool LockFileManager::processStillExecuting(StringRef Hostname, int PID) {
-#if LLVM_ON_UNIX && !defined(__ANDROID__)
+#if LLVM_ON_UNIX && !defined(__ANDROID__) && !defined(__ANDROID_NDK__)
   char MyHostname[256];
   MyHostname[255] = 0;
   MyHostname[0] = 0;
diff --git a/lib/Support/Unix/Memory.inc b/lib/Support/Unix/Memory.inc
index c9d89a8..2fa7c76 100644
--- a/lib/Support/Unix/Memory.inc
+++ b/lib/Support/Unix/Memory.inc
@@ -340,7 +340,7 @@ void Memory::InvalidateInstructionCache(const void *Addr,
   __clear_cache(const_cast<char *>(Start), const_cast<char *>(End));
 #  elif defined(__mips__)
   const char *Start = static_cast<const char *>(Addr);
-#    if defined(ANDROID)
+#    if defined(ANDROID) || defined(__ANDROID_NDK__)
   // The declaration of "cacheflush" in Android bionic:
   // extern int cacheflush(long start, long end, long flags);
   const char *End = Start + Len;
diff --git a/lib/Transforms/Hello/CMakeLists.txt b/lib/Transforms/Hello/CMakeLists.txt
index 3851b35..b74fb89 100644
--- a/lib/Transforms/Hello/CMakeLists.txt
+++ b/lib/Transforms/Hello/CMakeLists.txt
@@ -6,7 +6,7 @@ if( NOT LLVM_REQUIRES_RTTI )
   endif()
 endif()
 
-if(WIN32 OR CYGWIN)
+if(WIN32 OR CYGWIN OR __ANDROID_NDK__)
   set(LLVM_LINK_COMPONENTS Core Support)
 endif()
 
diff --git a/tools/bugpoint-passes/CMakeLists.txt b/tools/bugpoint-passes/CMakeLists.txt
index de68bb5..4b3d7df 100644
--- a/tools/bugpoint-passes/CMakeLists.txt
+++ b/tools/bugpoint-passes/CMakeLists.txt
@@ -10,7 +10,7 @@ if( NOT LLVM_REQUIRES_RTTI )
   endif()
 endif()
 
-if(WIN32 OR CYGWIN)
+if(WIN32 OR CYGWIN OR __ANDROID_NDK__)
   set(LLVM_LINK_COMPONENTS Core)
 endif()
 
diff --git a/utils/unittest/googletest/include/gtest/internal/gtest-port.h b/utils/unittest/googletest/include/gtest/internal/gtest-port.h
index f5bfd4e..617ec0e 100644
--- a/utils/unittest/googletest/include/gtest/internal/gtest-port.h
+++ b/utils/unittest/googletest/include/gtest/internal/gtest-port.h
@@ -233,7 +233,7 @@
 # define GTEST_OS_FREEBSD 1
 #elif defined __linux__
 # define GTEST_OS_LINUX 1
-# if defined(ANDROID) || defined(__ANDROID__)
+# if defined(ANDROID) || defined(__ANDROID__) || defined(__ANDROID_NDK__)
 #  define GTEST_OS_LINUX_ANDROID 1
 # endif  // ANDROID
 #elif defined __MVS__
@@ -271,7 +271,7 @@
 
 // Defines this to true iff Google Test can use POSIX regular expressions.
 #ifndef GTEST_HAS_POSIX_RE
-# define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS)
+# define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS && !defined(__ANDROID_NDK__))
 #endif
 
 #if GTEST_HAS_POSIX_RE
@@ -523,7 +523,7 @@
 #ifndef GTEST_HAS_CLONE
 // The user didn't tell us, so we need to figure it out.
 
-# if GTEST_OS_LINUX && !defined(__ia64__)
+# if GTEST_OS_LINUX && !defined(__ia64__) && !defined(__ANDROID_NDK__)
 #  define GTEST_HAS_CLONE 1
 # else
 #  define GTEST_HAS_CLONE 0


More information about the llvm-commits mailing list