Merge "Add tool to copy files in to fat16 images"
diff --git a/core/Makefile b/core/Makefile
index f9de658..4ed8947 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -2058,7 +2058,7 @@
 	$(hide) rm -rf $@ $(PRIVATE_LIST_FILE)
 	$(hide) mkdir -p $(dir $@) $(TARGET_OUT_UNSTRIPPED) $(dir $(PRIVATE_LIST_FILE))
 	$(hide) find $(TARGET_OUT_UNSTRIPPED) | sort >$(PRIVATE_LIST_FILE)
-	$(hide) $(SOONG_ZIP) -d -o $@ -C $(TARGET_OUT_UNSTRIPPED) -l $(PRIVATE_LIST_FILE)
+	$(hide) $(SOONG_ZIP) -d -o $@ -C . -l $(PRIVATE_LIST_FILE)
 
 # -----------------------------------------------------------------
 # A zip of the Android Apps. Not keeping full path so that we don't
diff --git a/core/clang/config.mk b/core/clang/config.mk
index 7113892..c2a0bf4 100644
--- a/core/clang/config.mk
+++ b/core/clang/config.mk
@@ -138,11 +138,6 @@
 # provides to Clang (for supporting features like -ftrapv).
 COMPILER_RT_CONFIG_EXTRA_STATIC_LIBRARIES := libcompiler_rt-extras
 
-ifeq ($(HOST_PREFER_32_BIT),true)
-# We don't have 32-bit prebuilt libLLVM/libclang, so force to build them from source.
-FORCE_BUILD_LLVM_COMPONENTS := true
-endif
-
 # A list of projects that are allowed to set LOCAL_CLANG to false.
 # INTERNAL_LOCAL_CLANG_EXCEPTION_PROJECTS is defined later in other config.mk.
 LOCAL_CLANG_EXCEPTION_PROJECTS = \
diff --git a/core/combo/arch/mips64/mips64r6.mk b/core/combo/arch/mips64/mips64r6.mk
index 9d9068c..42d6c9e 100644
--- a/core/combo/arch/mips64/mips64r6.mk
+++ b/core/combo/arch/mips64/mips64r6.mk
@@ -1,3 +1,3 @@
 # Configuration for Android on mips64r6.
 
-ARCH_MIPS_REV6 := true
+ARCH_MIPS64_REV6 := true
diff --git a/core/envsetup.mk b/core/envsetup.mk
index 3ecd219..a221fb9 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -298,11 +298,7 @@
 
 # The default host library path.
 # It always points to the path where we build libraries in the default bitness.
-ifeq ($(HOST_PREFER_32_BIT),true)
-HOST_LIBRARY_PATH := $($(HOST_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES)
-else
 HOST_LIBRARY_PATH := $(HOST_OUT_SHARED_LIBRARIES)
-endif
 
 # Out for HOST_CROSS_2ND_ARCH
 HOST_CROSS_2ND_ARCH_VAR_PREFIX := 2ND_
diff --git a/core/executable_prefer_symlink.mk b/core/executable_prefer_symlink.mk
index e59e8c2..9b9814e 100644
--- a/core/executable_prefer_symlink.mk
+++ b/core/executable_prefer_symlink.mk
@@ -33,11 +33,7 @@
   endif
 else
   my_symlink := $(addprefix $(HOST_OUT)/bin/, $(LOCAL_MODULE))
-  ifneq ($(HOST_PREFER_32_BIT),true)
-    my_src_binary_name := $(LOCAL_MODULE_STEM_64)
-  else
-    my_src_binary_name := $(LOCAL_MODULE_STEM_32)
-  endif
+  my_src_binary_name := $(LOCAL_MODULE_STEM_64)
 endif
 
 $(call symlink-file,$(my_module_path)/$(my_src_binary_name),$(my_src_binary_name),$(my_symlink))
diff --git a/core/fuzz_test.mk b/core/fuzz_test.mk
index c31e2e7..f6d6e9a 100644
--- a/core/fuzz_test.mk
+++ b/core/fuzz_test.mk
@@ -23,8 +23,8 @@
 $(error $(LOCAL_PATH): Do not set LOCAL_MODULE_PATH_64 when building test $(LOCAL_MODULE))
 endif
 
-LOCAL_MODULE_PATH_64 := $(TARGET_OUT_DATA_NATIVE_TESTS)/$(LOCAL_MODULE)
-LOCAL_MODULE_PATH_32 := $($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_DATA_NATIVE_TESTS)/$(LOCAL_MODULE)
+LOCAL_MODULE_PATH_64 := $(TARGET_OUT_DATA_NATIVE_TESTS)/fuzzers/$(LOCAL_MODULE)
+LOCAL_MODULE_PATH_32 := $($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_DATA_NATIVE_TESTS)/fuzzers/$(LOCAL_MODULE)
 
 ifndef LOCAL_MULTILIB
 ifndef LOCAL_32_BIT_ONLY
diff --git a/core/host_executable.mk b/core/host_executable.mk
index 78223eb..1480c2c 100644
--- a/core/host_executable.mk
+++ b/core/host_executable.mk
@@ -6,14 +6,10 @@
 
 ifndef LOCAL_MODULE_HOST_ARCH
 ifndef my_module_multilib
-ifeq ($(HOST_PREFER_32_BIT),true)
-my_module_multilib := 32
-else
 # By default we only build host module for the first arch.
 my_module_multilib := first
 endif
 endif
-endif
 
 ifeq ($(LOCAL_NO_FPIE),)
 LOCAL_LDFLAGS += $(HOST_FPIE_FLAGS)
diff --git a/core/host_shared_library.mk b/core/host_shared_library.mk
index df24b63..5da7913 100644
--- a/core/host_shared_library.mk
+++ b/core/host_shared_library.mk
@@ -6,14 +6,10 @@
 
 ifndef LOCAL_MODULE_HOST_ARCH
 ifndef my_module_multilib
-ifeq ($(HOST_PREFER_32_BIT),true)
-my_module_multilib := 32
-else
 # libraries default to building for both architecturess
 my_module_multilib := both
 endif
 endif
-endif
 
 LOCAL_2ND_ARCH_VAR_PREFIX :=
 include $(BUILD_SYSTEM)/module_arch_supported.mk
diff --git a/core/host_static_library.mk b/core/host_static_library.mk
index 61f5569..aa0421e 100644
--- a/core/host_static_library.mk
+++ b/core/host_static_library.mk
@@ -6,14 +6,10 @@
 
 ifndef LOCAL_MODULE_HOST_ARCH
 ifndef my_module_multilib
-ifeq ($(HOST_PREFER_32_BIT),true)
-my_module_multilib := 32
-else
 # libraries default to building for both architecturess
 my_module_multilib := both
 endif
 endif
-endif
 
 LOCAL_2ND_ARCH_VAR_PREFIX :=
 include $(BUILD_SYSTEM)/module_arch_supported.mk
diff --git a/core/soong.mk b/core/soong.mk
index 29a91e2..50831ba 100644
--- a/core/soong.mk
+++ b/core/soong.mk
@@ -53,7 +53,6 @@
 	echo '    "Schedboost": $(if $(strip $(ENABLE_SCHEDBOOST)),true,false),'; \
 	echo '    "Binder32bit": $(if $(BINDER32BIT),true,false),'; \
 	echo '    "DevicePrefer32BitExecutables": $(if $(filter true,$(TARGET_PREFER_32_BIT_EXECUTABLES)),true,false),'; \
-	echo '    "HostPrefer32BitExecutables": $(if $(filter true,$(HOST_PREFER_32_BIT)),true,false),'; \
 	echo '    "UseGoma": $(if $(filter-out false,$(USE_GOMA)),true,false),'; \
 	echo ''; \
 	echo '    "DeviceName": "$(TARGET_DEVICE)",'; \
diff --git a/target/board/generic_mips64/BoardConfig.mk b/target/board/generic_mips64/BoardConfig.mk
index ebc1675..ed9c9b3 100644
--- a/target/board/generic_mips64/BoardConfig.mk
+++ b/target/board/generic_mips64/BoardConfig.mk
@@ -31,7 +31,10 @@
 TARGET_2ND_ARCH := mips
 ifeq (,$(TARGET_2ND_ARCH_VARIANT))
 ifeq ($(TARGET_ARCH_VARIANT),mips64r6)
-TARGET_2ND_ARCH_VARIANT :=  mips32r6
+# Imgtec builds use 32r6 arch variant with Imgtec-maintained prebuilts/ndk library:
+# TARGET_2ND_ARCH_VARIANT := mips32r6
+# Aosp builds lack full set of mips32r6 NDK prebuilts, so use 32r2 abi:
+TARGET_2ND_ARCH_VARIANT :=  mips32r2-fp
 else
 TARGET_2ND_ARCH_VARIANT :=  mips32r2-fp
 endif
diff --git a/tools/releasetools/build_image.py b/tools/releasetools/build_image.py
index 9ee472b..a7b3fdd 100755
--- a/tools/releasetools/build_image.py
+++ b/tools/releasetools/build_image.py
@@ -109,7 +109,8 @@
   Args:
     partition_size: the size of the partition to be verified.
   Returns:
-    The size of the partition adjusted for verity metadata.
+    A tuple of the size of the partition adjusted for verity metadata, and
+    the size of verity metadata.
   """
   key = "%d %d" % (partition_size, fec_supported)
   if key in AdjustPartitionSizeForVerity.results:
@@ -121,27 +122,31 @@
 
   # verity tree and fec sizes depend on the partition size, which
   # means this estimate is always going to be unnecessarily small
-  lo = partition_size - GetVeritySize(hi, fec_supported)
+  verity_size = GetVeritySize(hi, fec_supported)
+  lo = partition_size - verity_size
   result = lo
 
   # do a binary search for the optimal size
   while lo < hi:
     i = ((lo + hi) // (2 * BLOCK_SIZE)) * BLOCK_SIZE
-    size = i + GetVeritySize(i, fec_supported)
-    if size <= partition_size:
+    v = GetVeritySize(i, fec_supported)
+    if i + v <= partition_size:
       if result < i:
         result = i
+        verity_size = v
       lo = i + BLOCK_SIZE
     else:
       hi = i
 
-  AdjustPartitionSizeForVerity.results[key] = result
-  return result
+  AdjustPartitionSizeForVerity.results[key] = (result, verity_size)
+  return (result, verity_size)
 
 AdjustPartitionSizeForVerity.results = {}
 
-def BuildVerityFEC(sparse_image_path, verity_path, verity_fec_path):
-  cmd = "fec -e %s %s %s" % (sparse_image_path, verity_path, verity_fec_path)
+def BuildVerityFEC(sparse_image_path, verity_path, verity_fec_path,
+                   padding_size):
+  cmd = "fec -e -p %d %s %s %s" % (padding_size, sparse_image_path,
+                                   verity_path, verity_fec_path)
   print cmd
   status, output = commands.getstatusoutput(cmd)
   if status:
@@ -204,7 +209,7 @@
 
 def BuildVerifiedImage(data_image_path, verity_image_path,
                        verity_metadata_path, verity_fec_path,
-                       fec_supported):
+                       padding_size, fec_supported):
   if not Append(verity_image_path, verity_metadata_path,
                 "Could not append verity metadata!"):
     return False
@@ -212,7 +217,7 @@
   if fec_supported:
     # build FEC for the entire partition, including metadata
     if not BuildVerityFEC(data_image_path, verity_image_path,
-                          verity_fec_path):
+                          verity_fec_path, padding_size):
       return False
 
     if not Append(verity_image_path, verity_fec_path, "Could not append FEC!"):
@@ -250,7 +255,7 @@
     True on success, False otherwise.
   """
   # get properties
-  image_size = prop_dict["partition_size"]
+  image_size = int(prop_dict["partition_size"])
   block_dev = prop_dict["verity_block_device"]
   signer_key = prop_dict["verity_key"] + ".pk8"
   if OPTIONS.verity_signer_path is not None:
@@ -281,10 +286,17 @@
     return False
 
   # build the full verified image
+  target_size = int(prop_dict["original_partition_size"])
+  verity_size = int(prop_dict["verity_size"])
+
+  padding_size = target_size - image_size - verity_size
+  assert padding_size >= 0
+
   if not BuildVerifiedImage(out_file,
                             verity_image_path,
                             verity_metadata_path,
                             verity_fec_path,
+                            padding_size,
                             fec_supported):
     shutil.rmtree(tempdir_name, ignore_errors=True)
     return False
@@ -355,12 +367,13 @@
   # verified.
   if verity_supported and is_verity_partition:
     partition_size = int(prop_dict.get("partition_size"))
-    adjusted_size = AdjustPartitionSizeForVerity(partition_size,
-                                                 verity_fec_supported)
+    (adjusted_size, verity_size) = AdjustPartitionSizeForVerity(partition_size,
+                                                                verity_fec_supported)
     if not adjusted_size:
       return False
     prop_dict["partition_size"] = str(adjusted_size)
     prop_dict["original_partition_size"] = str(partition_size)
+    prop_dict["verity_size"] = str(verity_size)
 
   if fs_type.startswith("ext"):
     build_command = ["mkuserimg.sh"]
diff --git a/tools/warn.py b/tools/warn.py
index 3a8ae66..ce78d5d 100755
--- a/tools/warn.py
+++ b/tools/warn.py
@@ -128,6 +128,9 @@
     { 'category':'C/C++',   'severity':severity.HIGH,     'members':[], 'option':'-fno-builtin',
         'description':'Incompatible declaration of built in function',
         'patterns':[r".*: warning: incompatible implicit declaration of built-in function .+"] },
+    { 'category':'C/C++',   'severity':severity.HIGH,     'members':[], 'option':'-Wincompatible-library-redeclaration',
+        'description':'Incompatible redeclaration of library function',
+        'patterns':[r".*: warning: incompatible redeclaration of library function .+"] },
     { 'category':'C/C++',   'severity':severity.HIGH,     'members':[], 'option':'',
         'description':'Null passed as non-null argument',
         'patterns':[r".*: warning: Null passed to a callee that requires a non-null"] },
@@ -362,6 +365,9 @@
     { 'category':'java',    'severity':severity.MEDIUM,   'members':[], 'option':'',
         'description':'Java: Unchecked conversion',
         'patterns':[r".*: warning: \[unchecked\] unchecked conversion"] },
+    { 'category':'java',   'severity':severity.MEDIUM,     'members':[], 'option':'',
+        'description':'_ used as an identifier',
+        'patterns':[r".*: warning: '_' used as an identifier"] },
 
     # Warnings from Error Prone.
     {'category': 'java',
@@ -1487,6 +1493,10 @@
     { 'category':'C/C++',   'severity':severity.LOW,      'members':[], 'option':'-Wcomment',
         'description':'Comment inside comment',
         'patterns':[r".*: warning: "".+"" within comment"] },
+    # Warning "value stored is never read" could be from clang-tidy or clang static analyzer.
+    { 'category':'C/C++',   'severity':severity.TIDY,      'members':[], 'option':'',
+        'description':'clang-tidy Value stored is never read',
+        'patterns':[r".*: warning: Value stored to .+ is never read.*clang-analyzer-deadcode.DeadStores"] },
     { 'category':'C/C++',   'severity':severity.LOW,      'members':[], 'option':'',
         'description':'Value stored is never read',
         'patterns':[r".*: warning: Value stored to .+ is never read"] },
@@ -1544,7 +1554,7 @@
                     r".*: warning: wrong type argument to increment"] },
     { 'category':'C/C++',   'severity':severity.MEDIUM,   'members':[], 'option':'-Wsign-promo',
         'description':'Overload resolution chose to promote from unsigned or enum to signed type' ,
-        'patterns':[r".*: warning: passing '.+' chooses 'int' over '.* int'"] },
+        'patterns':[r".*: warning: passing '.+' chooses '.+' over '.+'.*Wsign-promo"] },
     { 'category':'cont.',   'severity':severity.SKIP,     'members':[], 'option':'',
         'description':'',
         'patterns':[r".*: warning:   in call to '.+'"] },
@@ -1708,6 +1718,12 @@
     { 'category':'C/C++',   'severity':severity.MEDIUM,     'members':[], 'option':'',
         'description':'Result of malloc type incompatible with sizeof operand type',
         'patterns':[r".*: warning: Result of '.+' is converted to .+ incompatible with sizeof operand type"] },
+    { 'category':'C/C++',   'severity':severity.MEDIUM,     'members':[], 'option':'-Wfor-loop-analysis',
+        'description':'Variable used in loop condition not modified in loop body',
+        'patterns':[r".*: warning: variable '.+' used in loop condition.*Wfor-loop-analysis"] },
+    { 'category':'C/C++',   'severity':severity.MEDIUM,     'members':[], 'option':'',
+        'description':'Closing a previously closed file',
+        'patterns':[r".*: warning: Closing a previously closed file"] },
 
     { 'category':'C/C++',   'severity':severity.HARMLESS,     'members':[], 'option':'',
         'description':'Discarded qualifier from pointer target type',
@@ -1794,18 +1810,57 @@
         'description':'clang-tidy performance-unnecessary-value-param',
         'patterns':[r".*: .+\[performance-unnecessary-value-param\]$"] },
     { 'category':'C/C++',   'severity':severity.TIDY,     'members':[], 'option':'',
+        'description':'clang-analyzer Unreachable code',
+        'patterns':[r".*: warning: This statement is never executed.*UnreachableCode"] },
+    { 'category':'C/C++',   'severity':severity.TIDY,     'members':[], 'option':'',
+        'description':'clang-analyzer Size of malloc may overflow',
+        'patterns':[r".*: warning: .* size of .* may overflow .*MallocOverflow"] },
+    { 'category':'C/C++',   'severity':severity.TIDY,     'members':[], 'option':'',
+        'description':'clang-analyzer Stream pointer might be NULL',
+        'patterns':[r".*: warning: Stream pointer might be NULL .*unix.Stream"] },
+    { 'category':'C/C++',   'severity':severity.TIDY,     'members':[], 'option':'',
+        'description':'clang-analyzer Opened file never closed',
+        'patterns':[r".*: warning: Opened File never closed.*unix.Stream"] },
+    { 'category':'C/C++',   'severity':severity.TIDY,     'members':[], 'option':'',
+        'description':'clang-analyzer sozeof() on a pointer type',
+        'patterns':[r".*: warning: .*calls sizeof.* on a pointer type.*SizeofPtr"] },
+    { 'category':'C/C++',   'severity':severity.TIDY,     'members':[], 'option':'',
+        'description':'clang-analyzer Pointer arithmetic on non-array variables',
+        'patterns':[r".*: warning: Pointer arithmetic on non-array variables .*PointerArithm"] },
+    { 'category':'C/C++',   'severity':severity.TIDY,     'members':[], 'option':'',
+        'description':'clang-analyzer Subtraction of pointers of different memory chunks',
+        'patterns':[r".*: warning: Subtraction of two pointers .*PointerSub"] },
+    { 'category':'C/C++',   'severity':severity.TIDY,     'members':[], 'option':'',
+        'description':'clang-analyzer Access out-of-bound array element',
+        'patterns':[r".*: warning: Access out-of-bound array element .*ArrayBound"] },
+    { 'category':'C/C++',   'severity':severity.TIDY,     'members':[], 'option':'',
+        'description':'clang-analyzer Out of bound memory access',
+        'patterns':[r".*: warning: Out of bound memory access .*ArrayBoundV2"] },
+    { 'category':'C/C++',   'severity':severity.TIDY,     'members':[], 'option':'',
+        'description':'clang-analyzer Possible lock order reversal',
+        'patterns':[r".*: warning: .* Possible lock order reversal.*PthreadLock"] },
+    { 'category':'C/C++',   'severity':severity.TIDY,     'members':[], 'option':'',
+        'description':'clang-analyzer Argument is a pointer to uninitialized value',
+        'patterns':[r".*: warning: .* argument is a pointer to uninitialized value .*CallAndMessage"] },
+    { 'category':'C/C++',   'severity':severity.TIDY,     'members':[], 'option':'',
+        'description':'clang-analyzer cast to struct',
+        'patterns':[r".*: warning: Casting a non-structure type to a structure type .*CastToStruct"] },
+    { 'category':'C/C++',   'severity':severity.TIDY,     'members':[], 'option':'',
+        'description':'clang-analyzer call path problems',
+        'patterns':[r".*: warning: Call Path : .+"] },
+    { 'category':'C/C++',   'severity':severity.TIDY,     'members':[], 'option':'',
+        'description':'clang-analyzer other',
+        'patterns':[r".*: .+\[clang-analyzer-.+\]$",
+                    r".*: Call Path : .+$"] },
+    { 'category':'C/C++',   'severity':severity.TIDY,     'members':[], 'option':'',
         'description':'clang-tidy CERT',
         'patterns':[r".*: .+\[cert-.+\]$"] },
     { 'category':'C/C++',   'severity':severity.TIDY,     'members':[], 'option':'',
         'description':'clang-tidy llvm',
         'patterns':[r".*: .+\[llvm-.+\]$"] },
     { 'category':'C/C++',   'severity':severity.TIDY,     'members':[], 'option':'',
-        'description':'clang-tidy clang-diagnostic',
+        'description':'clang-diagnostic',
         'patterns':[r".*: .+\[clang-diagnostic-.+\]$"] },
-    { 'category':'C/C++',   'severity':severity.TIDY,     'members':[], 'option':'',
-        'description':'clang-tidy clang-analyzer',
-        'patterns':[r".*: .+\[clang-analyzer-.+\]$",
-                    r".*: Call Path : .+$"] },
 
     # catch-all for warnings this script doesn't know about yet
     { 'category':'C/C++',   'severity':severity.UNKNOWN,  'members':[], 'option':'',