Merge "Be more specific about POSIX obsolescence."
diff --git a/docs/status.md b/docs/status.md
index d9bd0af..cd40e2c 100644
--- a/docs/status.md
+++ b/docs/status.md
@@ -89,7 +89,6 @@
 pthread_setcancelstate
 pthread_setcanceltype
 pthread_testcancel
-sockatmark
 wordexp
 wordfree
 ```
diff --git a/libc/tools/check-symbols-glibc.py b/libc/tools/check-symbols-glibc.py
index 50bf36c..4de0181 100755
--- a/libc/tools/check-symbols-glibc.py
+++ b/libc/tools/check-symbols-glibc.py
@@ -221,6 +221,7 @@
   'shm_open', # disallowed by SELinux
   'shm_unlink', # disallowed by SELinux
   'setutxent', # no utmp on Android
+  'sockatmark', # obsolete (https://tools.ietf.org/html/rfc6093)
   'strfmon', # icu4c
   'strfmon_l', # icu4c
   'ulimit', # <ulimit.h> marked obsolescent
diff --git a/libdl/libdl.cpp b/libdl/libdl.cpp
index 97cdeb4..c834088 100644
--- a/libdl/libdl.cpp
+++ b/libdl/libdl.cpp
@@ -17,7 +17,6 @@
 #include <dlfcn.h>
 #include <link.h>
 #include <stdlib.h>
-#include <stdbool.h>
 #include <android/dlext.h>
 
 // These functions are exported by the loader
diff --git a/linker/linker.cpp b/linker/linker.cpp
index f6ca430..ec92c92 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -1621,11 +1621,13 @@
   }
 
   // Step 4-3: Add the new global group members to all the linked namespaces
-  for (auto si : new_global_group_members) {
+  if (namespaces != nullptr) {
     for (auto linked_ns : *namespaces) {
-      if (si->get_primary_namespace() != linked_ns) {
-        linked_ns->add_soinfo(si);
-        si->add_secondary_namespace(linked_ns);
+      for (auto si : new_global_group_members) {
+        if (si->get_primary_namespace() != linked_ns) {
+          linked_ns->add_soinfo(si);
+          si->add_secondary_namespace(linked_ns);
+        }
       }
     }
   }
diff --git a/linker/linker_main.cpp b/linker/linker_main.cpp
index 4799739..46cd60c 100644
--- a/linker/linker_main.cpp
+++ b/linker/linker_main.cpp
@@ -129,9 +129,8 @@
   if (path != nullptr) {
     // We have historically supported ':' as well as ' ' in LD_PRELOAD.
     g_ld_preload_names = android::base::Split(path, " :");
-    std::remove_if(g_ld_preload_names.begin(),
-                   g_ld_preload_names.end(),
-                   [] (const std::string& s) { return s.empty(); });
+    g_ld_preload_names.erase(std::remove_if(g_ld_preload_names.begin(), g_ld_preload_names.end(),
+                                            [](const std::string& s) { return s.empty(); }));
   }
 }
 
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index adc5ee4..697b84a 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -1496,4 +1496,9 @@
   ASSERT_SUBSTR(expected_dlerror.c_str(), dlerror());
 }
 
+TEST(dlfcn, dlopen_df_1_global) {
+  void* handle = dlopen("libtest_dlopen_df_1_global.so", RTLD_NOW);
+  ASSERT_TRUE(handle != nullptr) << dlerror();
+}
+
 #endif
diff --git a/tests/libs/Android.bp b/tests/libs/Android.bp
index 858f2b1..ba0b1aa 100644
--- a/tests/libs/Android.bp
+++ b/tests/libs/Android.bp
@@ -377,6 +377,26 @@
 }
 
 // -----------------------------------------------------------------------------
+// Library with DF_1_GLOBAL which will be dlopened
+// (note: libdl_test_df_1_global above will be included in DT_NEEDED)
+// -----------------------------------------------------------------------------
+cc_test_library {
+    name: "libtest_dlopen_df_1_global",
+    defaults: ["bionic_testlib_defaults"],
+    srcs: ["dl_df_1_global_dummy.cpp"],
+    ldflags: ["-Wl,-z,global"],
+
+    target: {
+        host: {
+            // TODO (dimitry): host ld.gold does not yet support -z global
+            // remove this line once it is updated.
+            ldflags: ["-fuse-ld=bfd"],
+        },
+    },
+}
+
+
+// -----------------------------------------------------------------------------
 // Library with weak function
 // -----------------------------------------------------------------------------
 cc_test_library {
diff --git a/tests/libs/dl_df_1_global_dummy.cpp b/tests/libs/dl_df_1_global_dummy.cpp
new file mode 100644
index 0000000..423247c
--- /dev/null
+++ b/tests/libs/dl_df_1_global_dummy.cpp
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+extern "C" int foo() {
+  return 1;
+}