Add a method to leave the symbol table in a library.

When LOCAL_STRIP_MODULE := keep_symbols is set, then the normal strip rules
will be modified so that only the .debug_* sections are removed. The original
symbol table is left alone.

This allows the compilation of certain libraries so that libbacktrace library
can provide meaningful names to functions.

Bug: 12958251
Change-Id: I82bdc304a463012e29086325ccb51163464cb4a9
diff --git a/core/dynamic_binary.mk b/core/dynamic_binary.mk
index 1d3b99e..32f2c91 100644
--- a/core/dynamic_binary.mk
+++ b/core/dynamic_binary.mk
@@ -116,6 +116,14 @@
 $(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
 	$(transform-to-stripped)
 else
+ifeq ($(my_strip_module),keep_symbols)
+# Strip only the debug frames, but leave the symbol table.
+$(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
+$(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY)
+$(strip_output): PRIVATE_READELF := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_READELF)
+$(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
+	$(transform-to-stripped-keep-symbols)
+else
 # Don't strip the binary, just copy it.  We can't skip this step
 # because a copy of the binary must appear at LOCAL_BUILT_MODULE.
 #
@@ -130,6 +138,7 @@
 	@echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
 	$(copy-file-to-target-with-cp)
 endif
+endif
 endif # my_strip_module