Merge "Revert "[MIPS] Support FR=0 emulation on FR=1 64-bit FP registers""
diff --git a/libc/Android.mk b/libc/Android.mk
index 2c8f554..de0bb41 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -580,6 +580,13 @@
 endif
 
 use_clang := $(USE_CLANG_PLATFORM_BUILD)
+
+# Clang/llvm has incompatible long double (fp128) for x86_64.
+# https://llvm.org/bugs/show_bug.cgi?id=23897
+ifeq ($(TARGET_ARCH),x86_64)
+  use_clang := false
+endif
+
 ifeq ($(use_clang),)
   use_clang := false
 endif
diff --git a/libm/Android.mk b/libm/Android.mk
index bc4c86d..7a7e3b0 100644
--- a/libm/Android.mk
+++ b/libm/Android.mk
@@ -3,6 +3,12 @@
 
 bionic_coverage := false
 
+# Clang/llvm has incompatible long double (fp128) for x86_64.
+# https://llvm.org/bugs/show_bug.cgi?id=23897
+ifeq ($(TARGET_ARCH),x86_64)
+libm_clang := false
+endif
+
 # -----------------------------------------------------------------------------
 # libm.a
 # -----------------------------------------------------------------------------
@@ -473,7 +479,7 @@
 LOCAL_C_INCLUDES += $(LOCAL_PATH)/upstream-freebsd/lib/msun/src/
 LOCAL_C_INCLUDES_64 += $(LOCAL_PATH)/upstream-freebsd/lib/msun/ld128/
 
-LOCAL_CLANG := true
+LOCAL_CLANG := $(libm_clang)
 LOCAL_ARM_MODE := arm
 LOCAL_CFLAGS := \
     -DFLT_EVAL_METHOD=0 \
@@ -514,7 +520,7 @@
 LOCAL_LDFLAGS := -Wl,--version-script,$(LOCAL_PATH)/libm.map
 
 LOCAL_MODULE := libm
-LOCAL_CLANG := true
+LOCAL_CLANG := $(libm_clang)
 LOCAL_SYSTEM_SHARED_LIBRARIES := libc
 LOCAL_WHOLE_STATIC_LIBRARIES := libm
 
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 0a9f6ed..2468829 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -2948,6 +2948,13 @@
 
 #if !defined(__LP64__)
   if (has_text_relocations) {
+    // Fail if app is targeting sdk version > 22
+    // TODO (dimitry): remove != __ANDROID_API__ check once http://b/20020312 is fixed
+    if (get_application_target_sdk_version() != __ANDROID_API__
+        && get_application_target_sdk_version() > 22) {
+      DL_ERR("%s: has text relocations", get_realpath());
+      return false;
+    }
     // Make segments writable to allow text relocations to work properly. We will later call
     // phdr_table_protect_segments() after all of them are applied and all constructors are run.
     DL_WARN("%s has text relocations. This is wasting memory and prevents "
diff --git a/tests/Android.mk b/tests/Android.mk
index 964a34a..8aba70b 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -49,9 +49,6 @@
 test_cppflags = \
     -std=gnu++11 \
 
-libBionicStandardTests_src_files_target := \
-    libdl_test.cpp \
-
 libBionicStandardTests_src_files := \
     arpa_inet_test.cpp \
     buffer_tests.cpp \
@@ -140,6 +137,11 @@
 libBionicStandardTests_ldlibs_host := \
     -lrt \
 
+# Clang/llvm has incompatible long double (fp128) for x86_64.
+# https://llvm.org/bugs/show_bug.cgi?id=23897
+# This affects most of math_test.cpp.
+libBionicStandardTests_clang_target := false
+
 module := libBionicStandardTests
 module_tag := optional
 build_type := target
@@ -275,6 +277,7 @@
     dlext_test.cpp \
     __cxa_thread_atexit_test.cpp \
     dlfcn_test.cpp \
+    libdl_test.cpp \
     pthread_dlfcn_test.cpp \
 
 bionic-unit-tests_cflags := $(test_cflags)
diff --git a/tests/libs/dlopen_b.cpp b/tests/libs/dlopen_b.cpp
index 34f2881..5291d81 100644
--- a/tests/libs/dlopen_b.cpp
+++ b/tests/libs/dlopen_b.cpp
@@ -1,7 +1,15 @@
 #include <dlfcn.h>
 extern "C" void *dlopen_b() {
+  // TODO (dimitry): this is to work around http://b/20049306
+  // remove once it is fixed
+  static int dummy = 0;
+
   // This is not supposed to succeed. Even though this library has DT_RUNPATH
   // for libtest_dt_runpath_x.so, it is not taked into account for dlopen.
   void *handle = dlopen("libtest_dt_runpath_x.so", RTLD_NOW);
-  return handle;
+  if (handle != nullptr) {
+    dummy++;
+    return handle;
+  }
+  return nullptr;
 }