Misc fixes for compiler_rt

1. Exclude lib/atomic-arm.c when building compiler_rt with clang.
   The file is to implement intrinsics generated by gcc
2. Exclude lib/atomic.c when building compiler_rt with gcc which
   has different sets of atomic intrinsics
3. Expand() logbl() as logb() because logbl doesn't exist in Android
   until API18, and "long double" is the same as "double"

Change-Id: I59921910a48f77e2e5f5da584a95cc64e6facf3f
diff --git a/lib/atomic-arm.c b/lib/atomic-arm.c
index 13d3b53..6487344 100644
--- a/lib/atomic-arm.c
+++ b/lib/atomic-arm.c
@@ -289,6 +289,7 @@
 }
 #endif
 
+#if !defined(__clang__)
 
 // gcc compatible interface
 // http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/_005f_005fsync-Builtins.html
@@ -446,4 +447,6 @@
 DEFINE_UNSUPPORT_SYNC_FUNC(val_compare_and_swap, int32_t, 2)
 DEFINE_UNSUPPORT_SYNC_FUNC(val_compare_and_swap, int64_t, 8)
 
+#endif // __clang__
+
 #endif // __arm__
diff --git a/lib/atomic.c b/lib/atomic.c
index a291f0d..832dc81 100644
--- a/lib/atomic.c
+++ b/lib/atomic.c
@@ -25,6 +25,8 @@
  *===----------------------------------------------------------------------===
  */
 
+#if defined(__clang__)
+
 #include <stdint.h>
 #include <string.h>
 
@@ -313,3 +315,5 @@
 #define OPTIMISED_CASE(n, lockfree, type) ATOMIC_RMW(n, lockfree, type, xor, ^)
 OPTIMISED_CASES
 #undef OPTIMISED_CASE
+
+#endif // __clang__
diff --git a/lib/int_math.h b/lib/int_math.h
index d6b4bda..adc0dc5 100644
--- a/lib/int_math.h
+++ b/lib/int_math.h
@@ -58,7 +58,13 @@
 
 #define crt_logb(x) __builtin_logb((x))
 #define crt_logbf(x) __builtin_logbf((x))
+#if defined(__ANDROID__)
+// In Android "long double" carries distinct signature but is treated the
+// same as double, and logbl doesn't exist until API 18
+#define crt_logbl(x) __builtin_logb((double)(x))
+#else
 #define crt_logbl(x) __builtin_logbl((x))
+#endif
 
 #define crt_scalbn(x, y) __builtin_scalbn((x), (y))
 #define crt_scalbnf(x, y) __builtin_scalbnf((x), (y))