OSDN Git Service

Build the shared library with --whole-archive
authorZach Johnson <zachoverflow@google.com>
Tue, 19 May 2015 21:49:37 +0000 (14:49 -0700)
committerAndre Eisenbach <eisenbach@google.com>
Mon, 8 Jun 2015 08:28:55 +0000 (01:28 -0700)
For stack static libraries, use LOCAL_WHOLE_STATIC_LIBRARIES
to ensure they get --whole-archive applied to them.

This means module symbols in static libraries won't be
removed by the linker and dlsym will find them.

This patch also removes the code hacks we needed to
trick the linker into including the module symbols in
the final shared library.

Change-Id: I2463d0e6fb38f1e75c8293179cf9d4ca33eda84e

btcore/src/module.c
main/Android.mk

index 2aa423a..745a368 100644 (file)
@@ -67,41 +67,10 @@ void module_management_stop(void) {
   pthread_mutex_destroy(&metadata_lock);
 }
 
-/* TODO: remove these externs and explicit checks once dlsym is fixed */
-/* TODO:
- *  (cont.) It looks like the dlsym bug is fixed now. However, without
- *  the code below (i.e. the module being referenced), the linker strips
- *  the module and thus dlsym will fail.
- */
-extern module_t bt_utils_module;
-extern module_t btif_config_module;
-extern module_t controller_module;
-extern module_t gki_module;
-extern module_t counter_module;
-extern module_t stack_config_module;
-extern module_t btsnoop_module;
-extern module_t hci_module;
-extern module_t bte_logmsg_module;
-extern module_t osi_module;
-
 const module_t *get_module(const char *name) {
   module_t* module = (module_t *)dlsym(RTLD_DEFAULT, name);
-  if (module) return module;
-
-  LOG_ERROR("%s dlsym() came up empty...", __func__);
-
-  if (!strcmp(name, "bt_utils_module")) return &bt_utils_module;
-  if (!strcmp(name, "btif_config_module")) return &btif_config_module;
-  if (!strcmp(name, "controller_module")) return &controller_module;
-  if (!strcmp(name, "gki_module")) return &gki_module;
-  if (!strcmp(name, "counter_module")) return &counter_module;
-  if (!strcmp(name, "stack_config_module")) return &stack_config_module;
-  if (!strcmp(name, "btsnoop_module")) return &btsnoop_module;
-  if (!strcmp(name, "hci_module")) return &hci_module;
-  if (!strcmp(name, "bte_logmsg_module")) return &bte_logmsg_module;
-  if (!strcmp(name, "osi_module")) return &osi_module;
-
-  return NULL;
+  assert(module);
+  return module;
 }
 
 bool module_init(const module_t *module) {
index d5cf8dd..04d4332 100644 (file)
@@ -134,6 +134,10 @@ LOCAL_SHARED_LIBRARIES := \
     libz
 
 LOCAL_STATIC_LIBRARIES := \
+    libtinyxml2 \
+    libbt-qcom_sbc_decoder
+
+LOCAL_WHOLE_STATIC_LIBRARIES := \
     libbt-brcm_bta \
     libbt-brcm_gki \
     libbt-brcm_stack \
@@ -141,9 +145,7 @@ LOCAL_STATIC_LIBRARIES := \
     libbt-hci \
     libbt-utils \
     libbtcore \
-    libosi \
-    libtinyxml2 \
-    libbt-qcom_sbc_decoder
+    libosi
 
 LOCAL_MODULE := bluetooth.default
 LOCAL_MODULE_RELATIVE_PATH := hw