Merge "libc: add /odm/bin to the DEFPATH"
diff --git a/android-changes-for-ndk-developers.md b/android-changes-for-ndk-developers.md
index 0620d9e..48800ca 100644
--- a/android-changes-for-ndk-developers.md
+++ b/android-changes-for-ndk-developers.md
@@ -360,23 +360,30 @@
 
 ## Enable logging of dlopen/dlsym and library loading errors for apps (Available in Android O)
 
-Starting with Android O it is possible to enable logging of all dlsym/dlopen calls
-for debuggable apps. Here is short instruction on how to do that:
+Starting with Android O it is possible to enable logging of dynamic
+linker activity for debuggable apps by setting a property corresponding
+to the fully-qualified name of the specific app:
 ```
-adb shell setprop debug.ld.app.com.example.myapp dlsym,dlopen,dlerror
+adb shell setprop debug.ld.app.com.example.myapp dlerror,dlopen,dlsym
 adb logcat
 ```
 
-Any subset of (dlsym,dlopen,dlerror) can be used.
+Any combination of `dlerror`, `dlopen`, and `dlsym` can be used. There's
+no separate `dlclose` option: `dlopen` covers both loading and unloading
+of libraries. Note also that `dlerror` doesn't correspond to actual
+calls of dlerror(3) but to any time the dynamic linker writes to its
+internal error buffer, so you'll see any errors the dynamic linker would
+have reported, even if the code you're debugging doesn't actually call
+dlerror(3) itself.
 
-On userdebug and eng builds it is possible to enable tracing for the whole system
-by using debug.ld.all system property instead of app-specific one:
+On userdebug and eng builds it is possible to enable tracing for the
+whole system by using the `debug.ld.all` system property instead of
+app-specific one. For example, to enable logging of all dlopen(3)
+(and thus dclose(3)) calls, and all failures, but not dlsym(3) calls:
 ```
 adb shell setprop debug.ld.all dlerror,dlopen
 ```
 
-enables logging of all errors and dlopen calls
-
 ## dlclose interacts badly with thread local variables with non-trivial destructors
 
 Android allows `dlclose` to unload a library even if there are still
diff --git a/libc/arch-arm/bionic/kuser_helper_on.S b/libc/arch-arm/bionic/kuser_helper_on.S
index 1e971a8..cff2073 100644
--- a/libc/arch-arm/bionic/kuser_helper_on.S
+++ b/libc/arch-arm/bionic/kuser_helper_on.S
@@ -25,14 +25,15 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-	.section	.note.android.kuser_helper_on,"a",%note
-	.align	2
-	.type	kuser_helper_on, %object
+
+  .section .note.android.kuser_helper_on,"a",%note
+  .balign 4
+  .type kuser_helper_on, %object
 kuser_helper_on:
-	.long	2f-1f			/* int32_t namesz */
-	.long	3f-2f			/* int32_t descsz */
-	.long	3			/* int32_t type */
-1:	.ascii	"Android\0"		/* char name[] */
-2:	.long	1	/* int32_t on */
+  .long 2f-1f         // int32_t namesz
+  .long 3f-2f         // int32_t descsz
+  .long 3             // int32_t type
+1:.ascii "Android\0"  // char name[]
+2:.long 1             // int32_t on
 3:
-	.size	kuser_helper_on, .-kuser_helper_on
+  .size kuser_helper_on, .-kuser_helper_on
diff --git a/libc/arch-common/bionic/crtbrand.S b/libc/arch-common/bionic/crtbrand.S
index 11bbfbe..4b4f99c 100644
--- a/libc/arch-common/bionic/crtbrand.S
+++ b/libc/arch-common/bionic/crtbrand.S
@@ -26,14 +26,14 @@
  * SUCH DAMAGE.
  */
 
-	.section	.note.android.ident,"a",%note
-	.align	2
-	.type	abitag, %object
+  .section .note.android.ident,"a",%note
+  .balign 4
+  .type abitag, %object
 abitag:
-	.long	2f-1f			/* int32_t namesz */
-	.long	3f-2f			/* int32_t descsz */
-	.long	1			/* int32_t type */
-1:	.ascii	"Android\0"		/* char name[] */
-2:	.long	PLATFORM_SDK_VERSION	/* int32_t android_api */
+  .long 2f-1f                 // int32_t namesz
+  .long 3f-2f                 // int32_t descsz
+  .long 1                     // int32_t type
+1:.ascii "Android\0"          // char name[]
+2:.long PLATFORM_SDK_VERSION  // int32_t android_api
 3:
-	.size	abitag, .-abitag
+  .size abitag, .-abitag
diff --git a/libc/bionic/__libc_current_sigrtmin.cpp b/libc/bionic/__libc_current_sigrtmin.cpp
index f3b2bf6..04caa89 100644
--- a/libc/bionic/__libc_current_sigrtmin.cpp
+++ b/libc/bionic/__libc_current_sigrtmin.cpp
@@ -28,10 +28,11 @@
 
 #include <signal.h>
 
-// POSIX timers use __SIGRTMIN + 0.
-// libbacktrace uses __SIGRTMIN + 1.
-// libcore uses __SIGRTMIN + 2.
-// __SIGRTMIN + 3 is reserved for triggering native stack dumps.
+// Realtime signals reserved for internal use:
+//   32 (__SIGRTMIN + 0)        POSIX timers
+//   33 (__SIGRTMIN + 1)        libbacktrace
+//   34 (__SIGRTMIN + 2)        libcore
+//   35 (__SIGRTMIN + 3)        debuggerd -b
 
 int __libc_current_sigrtmin(void) {
   // If you change this, also change __ndk_legacy___libc_current_sigrtmin
diff --git a/libc/bionic/fortify.cpp b/libc/bionic/fortify.cpp
index 4b7b776..985d47f 100644
--- a/libc/bionic/fortify.cpp
+++ b/libc/bionic/fortify.cpp
@@ -78,7 +78,7 @@
 //   http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
 //
 
-int __FD_ISSET_chk(int fd, fd_set* set, size_t set_size) {
+int __FD_ISSET_chk(int fd, const fd_set* set, size_t set_size) {
   __check_fd_set("FD_ISSET", fd, set_size);
   return FD_ISSET(fd, set);
 }
diff --git a/libc/include/sys/select.h b/libc/include/sys/select.h
index e919188..ac51d3f 100644
--- a/libc/include/sys/select.h
+++ b/libc/include/sys/select.h
@@ -37,39 +37,40 @@
 
 __BEGIN_DECLS
 
+typedef unsigned long fd_mask;
+
 #define FD_SETSIZE 1024
-#define NFDBITS (8 * sizeof(unsigned long))
-#define __FDSET_LONGS (FD_SETSIZE/NFDBITS)
+#define NFDBITS (8 * sizeof(fd_mask))
 
 typedef struct {
-  unsigned long fds_bits[__FDSET_LONGS];
+  fd_mask fds_bits[FD_SETSIZE/NFDBITS];
 } fd_set;
 
 #define __FDELT(fd) ((fd) / NFDBITS)
 #define __FDMASK(fd) (1UL << ((fd) % NFDBITS))
-#define __FDS_BITS(set) (__BIONIC_CAST(static_cast, fd_set*, set)->fds_bits)
+#define __FDS_BITS(type,set) (__BIONIC_CAST(static_cast, type, set)->fds_bits)
 
 /* Inline loop so we don't have to declare memset. */
 #define FD_ZERO(set) \
   do { \
     size_t __i; \
-    for (__i = 0; __i < __FDSET_LONGS; ++__i) { \
+    for (__i = 0; __i < sizeof(fd_set)/sizeof(fd_mask); ++__i) { \
       (set)->fds_bits[__i] = 0; \
     } \
   } while (0)
 
 void __FD_CLR_chk(int, fd_set*, size_t) __INTRODUCED_IN(21);
 void __FD_SET_chk(int, fd_set*, size_t) __INTRODUCED_IN(21);
-int __FD_ISSET_chk(int, fd_set*, size_t) __INTRODUCED_IN(21);
+int __FD_ISSET_chk(int, const fd_set*, size_t) __INTRODUCED_IN(21);
 
 #if defined(__BIONIC_FORTIFY) && __ANDROID_API__ >= __ANDROID_API_L__
 #define FD_CLR(fd, set) __FD_CLR_chk(fd, set, __bos(set))
 #define FD_SET(fd, set) __FD_SET_chk(fd, set, __bos(set))
 #define FD_ISSET(fd, set) __FD_ISSET_chk(fd, set, __bos(set))
 #else
-#define FD_CLR(fd, set) (__FDS_BITS(set)[__FDELT(fd)] &= ~__FDMASK(fd))
-#define FD_SET(fd, set) (__FDS_BITS(set)[__FDELT(fd)] |= __FDMASK(fd))
-#define FD_ISSET(fd, set) ((__FDS_BITS(set)[__FDELT(fd)] & __FDMASK(fd)) != 0)
+#define FD_CLR(fd, set) (__FDS_BITS(fd_set*,set)[__FDELT(fd)] &= ~__FDMASK(fd))
+#define FD_SET(fd, set) (__FDS_BITS(fd_set*,set)[__FDELT(fd)] |= __FDMASK(fd))
+#define FD_ISSET(fd, set) ((__FDS_BITS(const fd_set*,set)[__FDELT(fd)] & __FDMASK(fd)) != 0)
 #endif /* defined(__BIONIC_FORTIFY) && __ANDROID_API >= 21 */
 
 int select(int __fd_count, fd_set* __read_fds, fd_set* __write_fds, fd_set* __exception_fds, struct timeval* __timeout);
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 66ae191..7bf3a5b 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -90,13 +90,17 @@
 
 #if defined(__LP64__)
 static const char* const kSystemLibDir     = "/system/lib64";
+static const char* const kOdmLibDir        = "/odm/lib64";
 static const char* const kVendorLibDir     = "/vendor/lib64";
 static const char* const kAsanSystemLibDir = "/data/asan/system/lib64";
+static const char* const kAsanOdmLibDir    = "/data/asan/odm/lib64";
 static const char* const kAsanVendorLibDir = "/data/asan/vendor/lib64";
 #else
 static const char* const kSystemLibDir     = "/system/lib";
+static const char* const kOdmLibDir        = "/odm/lib";
 static const char* const kVendorLibDir     = "/vendor/lib";
 static const char* const kAsanSystemLibDir = "/data/asan/system/lib";
+static const char* const kAsanOdmLibDir    = "/data/asan/odm/lib";
 static const char* const kAsanVendorLibDir = "/data/asan/vendor/lib";
 #endif
 
@@ -104,6 +108,7 @@
 
 static const char* const kDefaultLdPaths[] = {
   kSystemLibDir,
+  kOdmLibDir,
   kVendorLibDir,
   nullptr
 };
@@ -111,6 +116,8 @@
 static const char* const kAsanDefaultLdPaths[] = {
   kAsanSystemLibDir,
   kSystemLibDir,
+  kAsanOdmLibDir,
+  kOdmLibDir,
   kAsanVendorLibDir,
   kVendorLibDir,
   nullptr
diff --git a/tests/sys_select_test.cpp b/tests/sys_select_test.cpp
index 4ad77f0..0eab876 100644
--- a/tests/sys_select_test.cpp
+++ b/tests/sys_select_test.cpp
@@ -179,3 +179,8 @@
 
   DelayedWriteCleanup(pid, fd);
 }
+
+TEST(sys_select, FD_ISSET_const) {
+  const fd_set none = {};
+  ASSERT_FALSE(FD_ISSET(atoi("0"), &none));
+}