Merge "Support mounting the odm image"
diff --git a/ndk/platforms/android-14/arch-arm/lib/libcompiler_rt-extras.a b/ndk/platforms/android-14/arch-arm/lib/libcompiler_rt-extras.a
new file mode 100644
index 0000000..97af575
--- /dev/null
+++ b/ndk/platforms/android-14/arch-arm/lib/libcompiler_rt-extras.a
Binary files differ
diff --git a/ndk/platforms/android-14/arch-x86/lib/libcompiler_rt-extras.a b/ndk/platforms/android-14/arch-x86/lib/libcompiler_rt-extras.a
new file mode 100644
index 0000000..310d717
--- /dev/null
+++ b/ndk/platforms/android-14/arch-x86/lib/libcompiler_rt-extras.a
Binary files differ
diff --git a/ndk/platforms/android-21/arch-arm/lib/libcompiler_rt-extras.a b/ndk/platforms/android-21/arch-arm/lib/libcompiler_rt-extras.a
new file mode 100644
index 0000000..97af575
--- /dev/null
+++ b/ndk/platforms/android-21/arch-arm/lib/libcompiler_rt-extras.a
Binary files differ
diff --git a/ndk/platforms/android-21/arch-arm64/lib/libcompiler_rt-extras.a b/ndk/platforms/android-21/arch-arm64/lib/libcompiler_rt-extras.a
new file mode 100644
index 0000000..408ca08
--- /dev/null
+++ b/ndk/platforms/android-21/arch-arm64/lib/libcompiler_rt-extras.a
Binary files differ
diff --git a/ndk/platforms/android-21/arch-x86/lib/libcompiler_rt-extras.a b/ndk/platforms/android-21/arch-x86/lib/libcompiler_rt-extras.a
new file mode 100644
index 0000000..310d717
--- /dev/null
+++ b/ndk/platforms/android-21/arch-x86/lib/libcompiler_rt-extras.a
Binary files differ
diff --git a/ndk/platforms/android-21/arch-x86_64/lib64/libcompiler_rt-extras.a b/ndk/platforms/android-21/arch-x86_64/lib64/libcompiler_rt-extras.a
new file mode 100644
index 0000000..c6a5325
--- /dev/null
+++ b/ndk/platforms/android-21/arch-x86_64/lib64/libcompiler_rt-extras.a
Binary files differ
diff --git a/vndk/tools/header-checker/header-abi-diff/src/abi_diff.cpp b/vndk/tools/header-checker/header-abi-diff/src/abi_diff.cpp
index ee3e229..eeacf3c 100644
--- a/vndk/tools/header-checker/header-abi-diff/src/abi_diff.cpp
+++ b/vndk/tools/header-checker/header-abi-diff/src/abi_diff.cpp
@@ -98,7 +98,7 @@
   AbiElementMap<const abi_util::RecordTypeIR *> record_types;
   // Iterate through the ODRListMap, if there is more than 1 element in the
   // list, we cannot really unique the type by name, so skip it. If not, add a
-  // map entry ODRListMapKey -> const Record(Enum)TypeIR *.
+  // map entry UniqueId -> const Record(Enum)TypeIR *.
   for (auto &it : tu->GetODRListMap()) {
     auto &odr_list = it.second;
     if (odr_list.size() != 1) {
@@ -107,12 +107,14 @@
     const abi_util::TypeIR *type = *(odr_list.begin());
     switch (type->GetKind()) {
       case abi_util::RecordTypeKind:
-        record_types.emplace(type->GetLinkerSetKey(),
-                             static_cast<const abi_util::RecordTypeIR *>(type));
+        record_types.emplace(
+            static_cast<const abi_util::RecordTypeIR *>(type)->GetUniqueId(),
+            static_cast<const abi_util::RecordTypeIR *>(type));
         break;
       case abi_util::EnumTypeKind:
-        enum_types.emplace(type->GetLinkerSetKey(),
-                           static_cast<const abi_util::EnumTypeIR *>(type));
+        enum_types.emplace(
+            static_cast<const abi_util::EnumTypeIR *>(type)->GetUniqueId(),
+            static_cast<const abi_util::EnumTypeIR *>(type));
         break;
       default:
         // Only user defined types should have ODR list entries.
diff --git a/vndk/tools/header-checker/tests/gen_all.py b/vndk/tools/header-checker/tests/gen_all.py
index b0b3ed6..78ba2b3 100755
--- a/vndk/tools/header-checker/tests/gen_all.py
+++ b/vndk/tools/header-checker/tests/gen_all.py
@@ -16,12 +16,9 @@
 INPUT_DIR = os.path.join(SCRIPT_DIR, 'input')
 EXPECTED_DIR = os.path.join(SCRIPT_DIR, 'expected')
 REFERENCE_DUMP_DIR = os.path.join(SCRIPT_DIR, 'reference_dumps')
-
-DEFAULT_CFLAGS = ['-x', 'c++', '-std=c++11']
-
 FILE_EXTENSIONS = ['h', 'hpp', 'hxx', 'cpp', 'cc', 'c']
 
-def make_and_copy_reference_dumps(module, default_cflags,
+def make_and_copy_reference_dumps(module, default_cflags=[],
                                   reference_dump_dir=REFERENCE_DUMP_DIR):
     lsdump_content = module.make_lsdump(default_cflags)
     return copy_reference_dump_content(module.get_name(), lsdump_content,
@@ -45,15 +42,14 @@
             output_path = os.path.join(EXPECTED_DIR, input_rel_path)
 
             print('generating', output_path, '...')
-            output_content = run_header_abi_dumper(input_path, True,
-                                                   DEFAULT_CFLAGS)
+            output_content = run_header_abi_dumper(input_path, True)
 
             os.makedirs(os.path.dirname(output_path), exist_ok=True)
             with open(output_path, 'w') as f:
                 f.write(output_content)
     modules = Module.get_test_modules()
     for module in modules:
-        make_and_copy_reference_dumps(module, DEFAULT_CFLAGS)
+        make_and_copy_reference_dumps(module)
 
     return 0
 
diff --git a/vndk/tools/header-checker/tests/integration/c_and_cpp/include/c_and_cpp.h b/vndk/tools/header-checker/tests/integration/c_and_cpp/include/c_and_cpp.h
index e852a4e..c4a7fcd 100644
--- a/vndk/tools/header-checker/tests/integration/c_and_cpp/include/c_and_cpp.h
+++ b/vndk/tools/header-checker/tests/integration/c_and_cpp/include/c_and_cpp.h
@@ -1,7 +1,13 @@
 #if INCLUDE_UNUSED_STRUCTS
+#if MAKE_UNUSED_STRUCT_C
+extern "C" {
+#endif
 struct UnusedStruct {
   int mUnusedMember;
 };
+#if MAKE_UNUSED_STRUCT_C
+}
+#endif
 #endif
 
 class Foo {
diff --git a/vndk/tools/header-checker/tests/integration/c_and_cpp/source1.cpp b/vndk/tools/header-checker/tests/integration/c_and_cpp/source1.cpp
index 8fa6700..a90e98e 100644
--- a/vndk/tools/header-checker/tests/integration/c_and_cpp/source1.cpp
+++ b/vndk/tools/header-checker/tests/integration/c_and_cpp/source1.cpp
@@ -1,4 +1,5 @@
 #include <c_and_cpp.h>
+#include <c_include.h>
 
 Foo foo(int *a, int *b) {
   // This does not make sense
diff --git a/vndk/tools/header-checker/tests/module.py b/vndk/tools/header-checker/tests/module.py
index 7c472aa..056f12e 100755
--- a/vndk/tools/header-checker/tests/module.py
+++ b/vndk/tools/header-checker/tests/module.py
@@ -137,6 +137,17 @@
         api = 'current',
     ),
     Module(
+        name = 'libc_and_cpp_with_unused_cstruct',
+        srcs = ['integration/c_and_cpp/source1.cpp',
+                'integration/c_and_cpp/source2.c',
+                ],
+        version_script = 'integration/c_and_cpp/map.txt',
+        export_include_dirs = ['integration/c_and_cpp/include'],
+        cflags = ['-DINCLUDE_UNUSED_STRUCTS=1', '-DMAKE_UNUSED_STRUCT_C=1'],
+        arch = '',
+        api = 'current',
+    ),
+    Module(
         name = 'libgolden_cpp',
         srcs = ['integration/cpp/gold/golden_1.cpp',
                 'integration/cpp/gold/high_volume_speaker.cpp',
diff --git a/vndk/tools/header-checker/tests/reference_dumps/arm/libreproducability.so.lsdump b/vndk/tools/header-checker/tests/reference_dumps/arm/libreproducability.so.lsdump
index 406c66c..673efb5 100644
--- a/vndk/tools/header-checker/tests/reference_dumps/arm/libreproducability.so.lsdump
+++ b/vndk/tools/header-checker/tests/reference_dumps/arm/libreproducability.so.lsdump
@@ -17,7 +17,7 @@
   access: public_access
   record_kind: struct_kind
   tag_info {
-    unique_id: "_ZTS11ShouldRepro"
+    unique_id: "ShouldRepro"
   }
 }
 builtin_types {
diff --git a/vndk/tools/header-checker/tests/reference_dumps/arm64/libreproducability.so.lsdump b/vndk/tools/header-checker/tests/reference_dumps/arm64/libreproducability.so.lsdump
index 406c66c..673efb5 100644
--- a/vndk/tools/header-checker/tests/reference_dumps/arm64/libreproducability.so.lsdump
+++ b/vndk/tools/header-checker/tests/reference_dumps/arm64/libreproducability.so.lsdump
@@ -17,7 +17,7 @@
   access: public_access
   record_kind: struct_kind
   tag_info {
-    unique_id: "_ZTS11ShouldRepro"
+    unique_id: "ShouldRepro"
   }
 }
 builtin_types {
diff --git a/vndk/tools/header-checker/tests/reference_dumps/mips/libreproducability.so.lsdump b/vndk/tools/header-checker/tests/reference_dumps/mips/libreproducability.so.lsdump
index 406c66c..673efb5 100644
--- a/vndk/tools/header-checker/tests/reference_dumps/mips/libreproducability.so.lsdump
+++ b/vndk/tools/header-checker/tests/reference_dumps/mips/libreproducability.so.lsdump
@@ -17,7 +17,7 @@
   access: public_access
   record_kind: struct_kind
   tag_info {
-    unique_id: "_ZTS11ShouldRepro"
+    unique_id: "ShouldRepro"
   }
 }
 builtin_types {
diff --git a/vndk/tools/header-checker/tests/reference_dumps/mips64/libreproducability.so.lsdump b/vndk/tools/header-checker/tests/reference_dumps/mips64/libreproducability.so.lsdump
index 406c66c..673efb5 100644
--- a/vndk/tools/header-checker/tests/reference_dumps/mips64/libreproducability.so.lsdump
+++ b/vndk/tools/header-checker/tests/reference_dumps/mips64/libreproducability.so.lsdump
@@ -17,7 +17,7 @@
   access: public_access
   record_kind: struct_kind
   tag_info {
-    unique_id: "_ZTS11ShouldRepro"
+    unique_id: "ShouldRepro"
   }
 }
 builtin_types {
diff --git a/vndk/tools/header-checker/tests/reference_dumps/x86/libreproducability.so.lsdump b/vndk/tools/header-checker/tests/reference_dumps/x86/libreproducability.so.lsdump
index 406c66c..673efb5 100644
--- a/vndk/tools/header-checker/tests/reference_dumps/x86/libreproducability.so.lsdump
+++ b/vndk/tools/header-checker/tests/reference_dumps/x86/libreproducability.so.lsdump
@@ -17,7 +17,7 @@
   access: public_access
   record_kind: struct_kind
   tag_info {
-    unique_id: "_ZTS11ShouldRepro"
+    unique_id: "ShouldRepro"
   }
 }
 builtin_types {
diff --git a/vndk/tools/header-checker/tests/reference_dumps/x86_64/libreproducability.so.lsdump b/vndk/tools/header-checker/tests/reference_dumps/x86_64/libreproducability.so.lsdump
index 406c66c..673efb5 100644
--- a/vndk/tools/header-checker/tests/reference_dumps/x86_64/libreproducability.so.lsdump
+++ b/vndk/tools/header-checker/tests/reference_dumps/x86_64/libreproducability.so.lsdump
@@ -17,7 +17,7 @@
   access: public_access
   record_kind: struct_kind
   tag_info {
-    unique_id: "_ZTS11ShouldRepro"
+    unique_id: "ShouldRepro"
   }
 }
 builtin_types {
diff --git a/vndk/tools/header-checker/tests/test.py b/vndk/tools/header-checker/tests/test.py
index a43c227..f6a7a1f 100755
--- a/vndk/tools/header-checker/tests/test.py
+++ b/vndk/tools/header-checker/tests/test.py
@@ -14,7 +14,6 @@
         run_abi_diff, run_header_abi_dumper)
 from module import Module
 from gen_all import make_and_copy_reference_dumps
-from gen_all import DEFAULT_CFLAGS
 
 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
 INPUT_DIR = os.path.join(SCRIPT_DIR, 'input')
@@ -64,7 +63,7 @@
     def create_ref_dump(self, name, dir_name, target_arch):
         module_bare = Module.get_test_module_by_name(name)
         module = Module.mutate_module_for_arch(module_bare, target_arch)
-        return make_and_copy_reference_dumps(module, DEFAULT_CFLAGS,
+        return make_and_copy_reference_dumps(module, [],
                                              dir_name)
 
     def get_or_create_ref_dump(self, name, target_arch, dir_name, create):
@@ -135,6 +134,12 @@
             "libc_and_cpp", "libc_and_cpp_with_unused_struct", 1,
             ['-check-all-apis'])
 
+    def test_libc_and_cpp_with_unused_struct_and_libc_and_cpp_with_unused_cstruct(self):
+        self.prepare_and_run_abi_diff_all_archs(
+            "libc_and_cpp_with_unused_struct",
+            "libc_and_cpp_with_unused_cstruct", 0,
+            ['-check-all-apis', '-allow-unreferenced-changes'])
+
     def test_libc_and_cpp_and_libc_and_cpp_with_unused_struct_check_all_advice(
         self):
         self.prepare_and_run_abi_diff_all_archs(
diff --git a/vndk/tools/header-checker/utils/utils.py b/vndk/tools/header-checker/utils/utils.py
index 83cd8ee..1b8cfdf 100644
--- a/vndk/tools/header-checker/utils/utils.py
+++ b/vndk/tools/header-checker/utils/utils.py
@@ -3,6 +3,8 @@
 import tempfile
 import os
 import subprocess
+import gzip
+import shutil
 
 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
 AOSP_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, *['..'] * 5))
@@ -22,6 +24,9 @@
 SOURCE_ABI_DUMP_EXT_END = '.lsdump'
 SOURCE_ABI_DUMP_EXT = SO_EXT + SOURCE_ABI_DUMP_EXT_END
 
+DEFAULT_CPPFLAGS = ['-x', 'c++', '-std=c++11']
+DEFAULT_CFLAGS = ['-std=gnu99']
+
 TARGET_ARCHS = ['arm', 'arm64', 'x86', 'x86_64', 'mips', 'mips64']
 
 def get_reference_dump_dir(reference_dump_dir_stem,
@@ -45,11 +50,11 @@
 
 def copy_reference_dump(lib_path, reference_dump_dir):
     reference_dump_path = os.path.join(reference_dump_dir,
-                                       os.path.basename(lib_path))
+                                       os.path.basename(lib_path)) + '.gz'
     os.makedirs(os.path.dirname(reference_dump_path), exist_ok=True)
     output_content = read_output_content(lib_path, AOSP_DIR)
-    with open(reference_dump_path, 'w') as f:
-        f.write(output_content)
+    with gzip.open(reference_dump_path, 'wb') as f:
+        f.write(bytes(output_content, 'utf-8'))
     print('Created abi dump at ', reference_dump_path)
     return reference_dump_path
 
@@ -64,6 +69,7 @@
     os.makedirs(os.path.dirname(reference_dump_path), exist_ok=True)
     with open(reference_dump_path, 'w') as f:
         f.write(output_content)
+
     print('Created abi dump at ', reference_dump_path)
     return reference_dump_path
 
@@ -85,11 +91,17 @@
 
 def run_header_abi_dumper_on_file(input_path, output_path,
                                   export_include_dirs = [], cflags =[]):
+    input_name, input_ext = os.path.splitext(input_path)
     cmd = ['header-abi-dumper', '-o', output_path, input_path,]
     for dir in export_include_dirs:
         cmd += ['-I', dir]
     cmd += ['--']
     cmd += cflags
+    if input_ext == '.cpp' or input_ext == '.cc' or input_ext == '.h':
+        cmd += DEFAULT_CPPFLAGS
+    else:
+        cmd += DEFAULT_CFLAGS
+
     for dir in BUILTIN_HEADERS_DIR:
         cmd += ['-isystem', dir]
     # export includes imply local includes