Merge "__cxa_finalize: skip fflush call on dlclose"
diff --git a/libc/bionic/grp_pwd.cpp b/libc/bionic/grp_pwd.cpp
index dadda49..ca6ea22 100644
--- a/libc/bionic/grp_pwd.cpp
+++ b/libc/bionic/grp_pwd.cpp
@@ -163,37 +163,19 @@
   return gr;
 }
 
-static passwd* android_id_to_passwd(passwd_state_t* state, unsigned id) {
+static const android_id_info* find_android_id_info(unsigned id) {
   for (size_t n = 0; n < android_id_count; ++n) {
     if (android_ids[n].aid == id) {
-      return android_iinfo_to_passwd(state, android_ids + n);
+      return &android_ids[n];
     }
   }
   return nullptr;
 }
 
-static passwd* android_name_to_passwd(passwd_state_t* state, const char* name) {
+static const android_id_info* find_android_id_info(const char* name) {
   for (size_t n = 0; n < android_id_count; ++n) {
     if (!strcmp(android_ids[n].name, name)) {
-      return android_iinfo_to_passwd(state, android_ids + n);
-    }
-  }
-  return nullptr;
-}
-
-static group* android_id_to_group(group_state_t* state, unsigned id) {
-  for (size_t n = 0; n < android_id_count; ++n) {
-    if (android_ids[n].aid == id) {
-      return android_iinfo_to_group(state, android_ids + n);
-    }
-  }
-  return nullptr;
-}
-
-static group* android_name_to_group(group_state_t* state, const char* name) {
-  for (size_t n = 0; n < android_id_count; ++n) {
-    if (!strcmp(android_ids[n].name, name)) {
-      return android_iinfo_to_group(state, android_ids + n);
+      return &android_ids[n];
     }
   }
   return nullptr;
@@ -332,15 +314,9 @@
   } else if (end[1] == 'i' && isdigit(end[2])) {
     // end will point to \0 if the strtoul below succeeds.
     appid = strtoul(end+2, &end, 10) + AID_ISOLATED_START;
-  } else {
-    for (size_t n = 0; n < android_id_count; n++) {
-      if (!strcmp(android_ids[n].name, end + 1)) {
-        appid = android_ids[n].aid;
-        // Move the end pointer to the null terminator.
-        end += strlen(android_ids[n].name) + 1;
-        break;
-      }
-    }
+  } else if (auto* android_id_info = find_android_id_info(end + 1); android_id_info != nullptr) {
+    appid = android_id_info->aid;
+    end += strlen(android_id_info->name) + 1;
   }
 
   // Check that the entire string was consumed by one of the 3 cases above.
@@ -370,11 +346,8 @@
   if (appid >= AID_ISOLATED_START) {
     snprintf(buffer, bufferlen, "u%u_i%u", userid, appid - AID_ISOLATED_START);
   } else if (appid < AID_APP_START) {
-    for (size_t n = 0; n < android_id_count; n++) {
-      if (android_ids[n].aid == appid) {
-        snprintf(buffer, bufferlen, "u%u_%s", userid, android_ids[n].name);
-        return;
-      }
+    if (auto* android_id_info = find_android_id_info(appid); android_id_info != nullptr) {
+      snprintf(buffer, bufferlen, "u%u_%s", userid, android_id_info->name);
     }
   } else {
     snprintf(buffer, bufferlen, "u%u_a%u", userid, appid - AID_APP_START);
@@ -391,11 +364,8 @@
   } else if (appid >= AID_CACHE_GID_START && appid <= AID_CACHE_GID_END) {
     snprintf(buffer, bufferlen, "u%u_a%u_cache", userid, appid - AID_CACHE_GID_START);
   } else if (appid < AID_APP_START) {
-    for (size_t n = 0; n < android_id_count; n++) {
-      if (android_ids[n].aid == appid) {
-        snprintf(buffer, bufferlen, "u%u_%s", userid, android_ids[n].name);
-        return;
-      }
+    if (auto* android_id_info = find_android_id_info(appid); android_id_info != nullptr) {
+      snprintf(buffer, bufferlen, "u%u_%s", userid, android_id_info->name);
     }
   } else {
     snprintf(buffer, bufferlen, "u%u_a%u", userid, appid - AID_APP_START);
@@ -520,12 +490,12 @@
     return nullptr;
   }
 
-  passwd* pw = android_id_to_passwd(state, uid);
-  if (pw != nullptr) {
-    return pw;
+  if (auto* android_id_info = find_android_id_info(uid); android_id_info != nullptr) {
+    return android_iinfo_to_passwd(state, android_id_info);
   }
+
   // Handle OEM range.
-  pw = oem_id_to_passwd(uid, state);
+  passwd* pw = oem_id_to_passwd(uid, state);
   if (pw != nullptr) {
     return pw;
   }
@@ -538,9 +508,8 @@
     return nullptr;
   }
 
-  passwd* pw = android_name_to_passwd(state, login);
-  if (pw != nullptr) {
-    return pw;
+  if (auto* android_id_info = find_android_id_info(login); android_id_info != nullptr) {
+    return android_iinfo_to_passwd(state, android_id_info);
   }
 
   if (vendor_passwd.FindByName(login, state)) {
@@ -550,7 +519,7 @@
   }
 
   // Handle OEM range.
-  pw = oem_id_to_passwd(oem_id_from_name(login), state);
+  passwd* pw = oem_id_to_passwd(oem_id_from_name(login), state);
   if (pw != nullptr) {
     return pw;
   }
@@ -634,12 +603,12 @@
 }
 
 static group* getgrgid_internal(gid_t gid, group_state_t* state) {
-  group* grp = android_id_to_group(state, gid);
-  if (grp != nullptr) {
-    return grp;
+  if (auto* android_id_info = find_android_id_info(gid); android_id_info != nullptr) {
+    return android_iinfo_to_group(state, android_id_info);
   }
+
   // Handle OEM range.
-  grp = oem_id_to_group(gid, state);
+  group* grp = oem_id_to_group(gid, state);
   if (grp != nullptr) {
     return grp;
   }
@@ -655,9 +624,8 @@
 }
 
 static group* getgrnam_internal(const char* name, group_state_t* state) {
-  group* grp = android_name_to_group(state, name);
-  if (grp != nullptr) {
-    return grp;
+  if (auto* android_id_info = find_android_id_info(name); android_id_info != nullptr) {
+    return android_iinfo_to_group(state, android_id_info);
   }
 
   if (vendor_group.FindByName(name, state)) {
@@ -667,7 +635,7 @@
   }
 
   // Handle OEM range.
-  grp = oem_id_to_group(oem_id_from_name(name), state);
+  group* grp = oem_id_to_group(oem_id_from_name(name), state);
   if (grp != nullptr) {
     return grp;
   }
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index b229cda..1f099cf 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -232,6 +232,7 @@
     "LD_AOUT_LIBRARY_PATH",
     "LD_AOUT_PRELOAD",
     "LD_AUDIT",
+    "LD_CONFIG_FILE",
     "LD_DEBUG",
     "LD_DEBUG_OUTPUT",
     "LD_DYNAMIC_WEAK",
@@ -242,6 +243,7 @@
     "LD_SHOW_AUXV",
     "LD_USE_LOAD_BIAS",
     "LIBC_DEBUG_MALLOC_OPTIONS",
+    "LIBC_HOOKS_ENABLE",
     "LOCALDOMAIN",
     "LOCPATH",
     "MALLOC_CHECK_",
diff --git a/libc/bionic/pthread_getschedparam.cpp b/libc/bionic/pthread_getschedparam.cpp
index ed1853b..765287f 100644
--- a/libc/bionic/pthread_getschedparam.cpp
+++ b/libc/bionic/pthread_getschedparam.cpp
@@ -28,9 +28,11 @@
 
 #include <errno.h>
 
+#include "private/bionic_defs.h"
 #include "private/ErrnoRestorer.h"
 #include "pthread_internal.h"
 
+__BIONIC_WEAK_FOR_NATIVE_BRIDGE
 int pthread_getschedparam(pthread_t t, int* policy, sched_param* param) {
   ErrnoRestorer errno_restorer;
 
diff --git a/libc/bionic/pthread_setschedparam.cpp b/libc/bionic/pthread_setschedparam.cpp
index 8a02728..656fe32 100644
--- a/libc/bionic/pthread_setschedparam.cpp
+++ b/libc/bionic/pthread_setschedparam.cpp
@@ -30,9 +30,11 @@
 #include <pthread.h>
 #include <sched.h>
 
+#include "private/bionic_defs.h"
 #include "private/ErrnoRestorer.h"
 #include "pthread_internal.h"
 
+__BIONIC_WEAK_FOR_NATIVE_BRIDGE
 int pthread_setschedparam(pthread_t t, int policy, const sched_param* param) {
   ErrnoRestorer errno_restorer;
 
@@ -42,6 +44,7 @@
   return (sched_setscheduler(tid, policy, param) == -1) ? errno : 0;
 }
 
+__BIONIC_WEAK_FOR_NATIVE_BRIDGE
 int pthread_setschedprio(pthread_t t, int priority) {
   ErrnoRestorer errno_restorer;