Add -DLIBELF_MMAP to enable mmap access for the symbol tables.

Also disabled new elfutil interface to probe kernel modules since
Bionic doesn't have stdio_ext support.

Change-Id: Ia4e20cd19c22604904d233317f64ff30d0d2d069
diff --git a/CleanSpec.mk b/CleanSpec.mk
index 79045ff..a97802d 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -65,6 +65,11 @@
 $(call add-clean-step, rm -rf $(OUT)/obj/STATIC_LIBRARIES/libebl_intermediates)
 $(call add-clean-step, rm -rf $(OUT)/obj/EXECUTABLES/perf_intermediates)
 
+$(call add-clean-step, rm -rf $(ANDROID_HOST_OUT)/obj/STATIC_LIBRARIES/libperf_intermediates)
+$(call add-clean-step, rm -rf $(ANDROID_HOST_OUT)/obj/EXECUTABLES/perf_intermediates)
+$(call add-clean-step, rm -rf $(OUT)/obj/STATIC_LIBRARIES/libperf_intermediates)
+$(call add-clean-step, rm -rf $(OUT)/obj/EXECUTABLES/perf_intermediates)
+
 # ************************************************
 # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
 # ************************************************
diff --git a/perf-3.12.0/tools/perf/Android.mk b/perf-3.12.0/tools/perf/Android.mk
index 774fd30..9d35950 100644
--- a/perf-3.12.0/tools/perf/Android.mk
+++ b/perf-3.12.0/tools/perf/Android.mk
@@ -90,6 +90,7 @@
 	util/strlist.c \
 	util/svghelper.c \
 	util/symbol.c \
+	util/symbol-elf.c \
 	util/sysfs.c \
 	util/target.c \
 	util/thread.c \
@@ -126,16 +127,13 @@
 common_predefined_macros := -DDWARF_SUPPORT -DPYTHON='""' -DBINDIR='""' \
 	-DETC_PERFCONFIG='""' -DPREFIX='""' -DPERF_EXEC_PATH='""' \
 	-DPERF_HTML_PATH='""' -DPERF_MAN_PATH='""' -DPERF_INFO_PATH='""' \
-	-DPERF_VERSION='"perf.3.12_android"' -DHAVE_ELF_GETPHDRNUM
+	-DPERF_VERSION='"perf.3.12_android"' -DHAVE_ELF_GETPHDRNUM \
+	-DLIBELF_SUPPORT -DLIBELF_MMAP
 
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := $(libperf_src_files)
 
-# TODO on-device symbolization is having issues as samples are attributed to
-# wrong DSOs
-LOCAL_SRC_FILES += util/symbol-minimal.c
-
 # disable modules not used by Android
 LOCAL_CFLAGS := $(common_disabled_macros)
 
@@ -159,18 +157,12 @@
 
 LOCAL_SRC_FILES := $(libperf_src_files)
 
-# perform symbolization on the host
-LOCAL_SRC_FILES += util/symbol-elf.c
-
 # disable modules not used by Android
 LOCAL_CFLAGS := $(common_disabled_macros)
 
 # predefined macros
 LOCAL_CFLAGS += $(common_predefined_macros)
 
-# needed by symbolization
-LOCAL_CFLAGS += -DLIBELF_SUPPORT
-
 LOCAL_CFLAGS += $(common_compiler_flags)
 
 LOCAL_C_INCLUDES := $(common_perf_headers) $(common_elfutil_headers)
diff --git a/perf-3.12.0/tools/perf/util/probe-finder.c b/perf-3.12.0/tools/perf/util/probe-finder.c
index f069273..b657aae 100644
--- a/perf-3.12.0/tools/perf/util/probe-finder.c
+++ b/perf-3.12.0/tools/perf/util/probe-finder.c
@@ -147,7 +147,13 @@
 	return -ENOENT;
 }
 
-#if _ELFUTILS_PREREQ(0, 148)
+/*
+ * ANDROID LOCAL PATCH
+ * Bionic doesn't have stdio_ext.h which is used by dwfl_linux_kernel_find_elf.
+ * So we just disable the new feature here even though we are pairing perf with
+ * elfutils 0.153 now.
+ */
+#if _ELFUTILS_PREREQ(0, 148) && 0
 /* This method is buggy if elfutils is older than 0.148 */
 static int __linux_kernel_find_elf(Dwfl_Module *mod,
 				   void **userdata,