Fix build (take two).

Make sure __netdClientDispatch is defined in the same set of libraries that
refer to it (e.g.: with connect.cpp).

(cherry picked from commit 8205a61248973ac13716ae80e712c80e126b0541)

Change-Id: I86d7bf2df5bde09f75a35b204eac0e1361747e22
diff --git a/libc/Android.mk b/libc/Android.mk
index 47c0d90..9eacb54 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -142,6 +142,7 @@
     bionic/mkfifo.cpp \
     bionic/mknod.cpp \
     bionic/mntent.cpp \
+    bionic/NetdClientDispatch.cpp \
     bionic/open.cpp \
     bionic/pause.cpp \
     bionic/pipe.cpp \
@@ -847,7 +848,6 @@
     bionic/dlmalloc.c \
     bionic/malloc_debug_common.cpp \
     bionic/libc_init_static.cpp \
-    bionic/NetdClient.cpp \
 
 LOCAL_CFLAGS := $(libc_common_cflags) \
                 -DLIBC_STATIC
diff --git a/libc/bionic/NetdClient.cpp b/libc/bionic/NetdClient.cpp
index 56d8244..6826ee8 100644
--- a/libc/bionic/NetdClient.cpp
+++ b/libc/bionic/NetdClient.cpp
@@ -14,24 +14,14 @@
  * limitations under the License.
  */
 
+#ifdef LIBC_STATIC
+#error NetdClient.cpp should NOT be included in static libc builds.
+#endif
+
 #include <private/NetdClient.h>
 #include <private/libc_logging.h>
 #include <pthread.h>
 
-#ifdef __i386__
-#define __socketcall __attribute__((__cdecl__))
-#else
-#define __socketcall
-#endif
-
-extern "C" __socketcall int __connect(int, const sockaddr*, socklen_t);
-
-NetdClientDispatch __netdClientDispatch __attribute__((aligned(32))) = {
-    __connect
-};
-
-#ifndef LIBC_STATIC
-
 #include <dlfcn.h>
 
 template <typename FunctionType>
@@ -56,13 +46,9 @@
 
 static pthread_once_t netdClientInitOnce = PTHREAD_ONCE_INIT;
 
-#endif  // LIBC_STATIC
-
 extern "C" __LIBC_HIDDEN__ void netdClientInit() {
-#ifndef LIBC_STATIC
     if (pthread_once(&netdClientInitOnce, netdClientInitImpl)) {
         __libc_format_log(ANDROID_LOG_ERROR, "netdClient",
                           "Unable to initialize netd_client component.");
     }
-#endif  // LIBC_STATIC
 }
diff --git a/libc/bionic/NetdClientDispatch.cpp b/libc/bionic/NetdClientDispatch.cpp
new file mode 100644
index 0000000..31728d2
--- /dev/null
+++ b/libc/bionic/NetdClientDispatch.cpp
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+#include <private/NetdClient.h>
+
+#ifdef __i386__
+#define __socketcall __attribute__((__cdecl__))
+#else
+#define __socketcall
+#endif
+
+extern "C" __socketcall int __connect(int, const sockaddr*, socklen_t);
+
+NetdClientDispatch __netdClientDispatch __attribute__((aligned(32))) = {
+    __connect
+};