simpleperf: use libbacktrace_offline static library.

Device may not have libbacktrace_offline shared library, so always
using libbacktrace_offline static library.
Use simpleperf namespace to avoid conflicts with ThreadEntry in
libbacktrace.

Bug: 28152982
Change-Id: Ia2cdbee3b28556c790ccd7b061a801ed96f9b97c
diff --git a/simpleperf/Android.mk b/simpleperf/Android.mk
index 62c3782..ac5ceda 100644
--- a/simpleperf/Android.mk
+++ b/simpleperf/Android.mk
@@ -32,13 +32,14 @@
 
 simpleperf_shared_libraries_target := \
   libbacktrace \
-  libbacktrace_offline \
+  libunwind \
   libbase \
   liblog \
   libutils \
   libLLVM \
 
 simpleperf_static_libraries_target := \
+  libbacktrace_offline \
   liblzma \
   libziparchive \
   libz \
@@ -46,13 +47,13 @@
 static_simpleperf_static_libraries_target := \
   libbacktrace_offline \
   libbacktrace \
+  libunwind \
   libziparchive \
   libz \
   libbase \
   libcutils \
   liblog \
   libutils \
-  libunwind \
   liblzma \
   libLLVMObject \
   libLLVMBitReader \
@@ -62,16 +63,6 @@
   libLLVMSupport \
   libc \
 
-simpleperf_shared_libraries_host_linux := \
-  libbacktrace_offline \
-  libbacktrace \
-
-simpleperf_shared_libraries_host_darwin := \
-  libLLVM \
-
-simpleperf_shared_libraries_host_windows := \
-  libLLVM \
-
 simpleperf_static_libraries_host := \
   libziparchive-host \
   libbase \
@@ -79,6 +70,18 @@
   liblzma \
   libz \
   libutils \
+  libLLVMObject \
+  libLLVMBitReader \
+  libLLVMMC \
+  libLLVMMCParser \
+  libLLVMCore \
+  libLLVMSupport \
+
+simpleperf_static_libraries_host_linux := \
+  libbacktrace_offline \
+  libbacktrace \
+  libunwind \
+  libcutils \
 
 simpleperf_ldlibs_host_linux := -lrt
 
@@ -164,9 +167,7 @@
 LOCAL_SRC_FILES_linux := $(libsimpleperf_src_files_linux)
 LOCAL_SRC_FILES_windows := $(libsimpleperf_src_files_windows)
 LOCAL_STATIC_LIBRARIES := $(simpleperf_static_libraries_host)
-LOCAL_SHARED_LIBRARIES_darwin := $(simpleperf_shared_libraries_host_darwin)
-LOCAL_SHARED_LIBRARIES_linux := $(simpleperf_shared_libraries_host_linux)
-LOCAL_SHARED_LIBRARIES_windows := $(simpleperf_shared_libraries_host_windows)
+LOCAL_STATIC_LIBRARIES_linux := $(simpleperf_static_libraries_host_linux)
 LOCAL_LDLIBS_linux := $(simpleperf_ldlibs_host_linux)
 LOCAL_MULTILIB := first
 include $(LLVM_HOST_BUILD_MK)
@@ -217,11 +218,10 @@
 LOCAL_CPPFLAGS_windows := $(simpleperf_cppflags_host_windows)
 LOCAL_SRC_FILES := main.cpp
 LOCAL_STATIC_LIBRARIES := libsimpleperf $(simpleperf_static_libraries_host)
-LOCAL_SHARED_LIBRARIES_darwin := $(simpleperf_shared_libraries_host_darwin)
-LOCAL_SHARED_LIBRARIES_linux := $(simpleperf_shared_libraries_host_linux)
-LOCAL_SHARED_LIBRARIES_windows := $(simpleperf_shared_libraries_host_windows)
+LOCAL_STATIC_LIBRARIES_linux := $(simpleperf_static_libraries_host_linux)
 LOCAL_LDLIBS_linux := $(simpleperf_ldlibs_host_linux)
 LOCAL_MULTILIB := first
+include $(LLVM_HOST_BUILD_MK)
 include $(BUILD_HOST_EXECUTABLE)
 
 
@@ -276,11 +276,10 @@
 LOCAL_SRC_FILES := $(simpleperf_unit_test_src_files)
 LOCAL_SRC_FILES_linux := $(simpleperf_unit_test_src_files_linux)
 LOCAL_STATIC_LIBRARIES := libsimpleperf $(simpleperf_static_libraries_host)
-LOCAL_SHARED_LIBRARIES_darwin := $(simpleperf_shared_libraries_host_darwin)
-LOCAL_SHARED_LIBRARIES_linux := $(simpleperf_shared_libraries_host_linux)
-LOCAL_SHARED_LIBRARIES_windows := $(simpleperf_shared_libraries_host_windows)
+LOCAL_STATIC_LIBRARIES_linux := $(simpleperf_static_libraries_host_linux)
 LOCAL_LDLIBS_linux := $(simpleperf_ldlibs_host_linux)
 LOCAL_MULTILIB := first
+include $(LLVM_HOST_BUILD_MK)
 include $(BUILD_HOST_NATIVE_TEST)
 
 
@@ -309,9 +308,10 @@
 LOCAL_CPPFLAGS_linux := $(simpleperf_cppflags_host_linux)
 LOCAL_SRC_FILES := $(simpleperf_cpu_hotplug_test_src_files)
 LOCAL_STATIC_LIBRARIES := libsimpleperf $(simpleperf_static_libraries_host)
-LOCAL_SHARED_LIBRARIES_linux := $(simpleperf_shared_libraries_host_linux)
+LOCAL_STATIC_LIBRARIES_linux := $(simpleperf_static_libraries_host_linux)
 LOCAL_LDLIBS_linux := $(simpleperf_ldlibs_host_linux)
 LOCAL_MULTILIB := first
+include $(LLVM_HOST_BUILD_MK)
 include $(BUILD_HOST_NATIVE_TEST)
 
 
@@ -344,7 +344,7 @@
 LOCAL_CPPFLAGS_linux := $(simpleperf_cppflags_host_linux)
 LOCAL_SRC_FILES := $(libsimpleperf_cts_test_src_files)
 LOCAL_STATIC_LIBRARIES := $(simpleperf_static_libraries_host)
-LOCAL_SHARED_LIBRARIES_linux := $(simpleperf_shared_libraries_host_linux)
+LOCAL_STATIC_LIBRARIES_linux := $(simpleperf_static_libraries_host_linux)
 LOCAL_LDLIBS_linux := $(simpleperf_ldlibs_host_linux)
 LOCAL_MULTILIB := both
 include $(LLVM_HOST_BUILD_MK)
diff --git a/simpleperf/dwarf_unwind.h b/simpleperf/dwarf_unwind.h
index c725723..ba40b87 100644
--- a/simpleperf/dwarf_unwind.h
+++ b/simpleperf/dwarf_unwind.h
@@ -21,7 +21,11 @@
 
 #include "perf_regs.h"
 
+namespace simpleperf {
 struct ThreadEntry;
+}
+
+using ThreadEntry = simpleperf::ThreadEntry;
 
 std::vector<uint64_t> UnwindCallChain(ArchType arch, const ThreadEntry& thread, const RegSet& regs,
                                       const std::vector<char>& stack, bool strict_arch_check);
diff --git a/simpleperf/thread_tree.cpp b/simpleperf/thread_tree.cpp
index 3134874..daf3ff5 100644
--- a/simpleperf/thread_tree.cpp
+++ b/simpleperf/thread_tree.cpp
@@ -24,6 +24,8 @@
 #include "perf_event.h"
 #include "record.h"
 
+namespace simpleperf {
+
 bool MapComparator::operator()(const MapEntry* map1, const MapEntry* map2) const {
   if (map1->start_addr != map2->start_addr) {
     return map1->start_addr < map2->start_addr;
@@ -207,6 +209,8 @@
   user_dso_tree_.clear();
 }
 
+}  // namespace simpleperf
+
 void BuildThreadTree(const Record& record, ThreadTree* thread_tree) {
   if (record.header.type == PERF_RECORD_MMAP) {
     const MmapRecord& r = *static_cast<const MmapRecord*>(&record);
diff --git a/simpleperf/thread_tree.h b/simpleperf/thread_tree.h
index 3652bbc..de10138 100644
--- a/simpleperf/thread_tree.h
+++ b/simpleperf/thread_tree.h
@@ -25,6 +25,8 @@
 
 #include "dso.h"
 
+namespace simpleperf {
+
 struct MapEntry {
   uint64_t start_addr;
   uint64_t len;
@@ -97,6 +99,12 @@
   Symbol unknown_symbol_;
 };
 
+}  // namespace simpleperf
+
+using MapEntry = simpleperf::MapEntry;
+using ThreadEntry = simpleperf::ThreadEntry;
+using ThreadTree = simpleperf::ThreadTree;
+
 struct Record;
 
 void BuildThreadTree(const Record& record, ThreadTree* thread_tree);