Merge "Don't fail build of otatools if there are no device certificates"
diff --git a/core/Makefile b/core/Makefile
index 9c562a8..36b23ee 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -838,7 +838,7 @@
   $(hide) cp -f $(recovery_initrc) $(TARGET_RECOVERY_ROOT_OUT)/
   $(hide) rm -f $(TARGET_RECOVERY_ROOT_OUT)/sepolicy
   $(hide) cp -f $(recovery_sepolicy) $(TARGET_RECOVERY_ROOT_OUT)/sepolicy
-  $(hide) cp $(TARGET_ROOT_OUT)/init.recovery.*.rc $(TARGET_RECOVERY_ROOT_OUT)/ | true # Ignore error when the src file doesn't exist.
+  $(hide) cp $(TARGET_ROOT_OUT)/init.recovery.*.rc $(TARGET_RECOVERY_ROOT_OUT)/ || true # Ignore error when the src file doesn't exist.
   $(hide) mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/res
   $(hide) rm -rf $(TARGET_RECOVERY_ROOT_OUT)/res/*
   $(hide) cp -rf $(recovery_resources_common)/* $(TARGET_RECOVERY_ROOT_OUT)/res
diff --git a/core/binary.mk b/core/binary.mk
index 92b08fa..15d5d1e 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -294,24 +294,14 @@
 # clean build of your module after toggling it.
 ifeq ($(NATIVE_COVERAGE),true)
     ifeq ($(my_native_coverage),true)
+        # Note that clang coverage doesn't play nicely with acov out of the box.
+        # Clang apparently generates .gcno files that aren't compatible with
+        # gcov-4.8.  This can be solved by installing gcc-4.6 and invoking lcov
+        # with `--gcov-tool /usr/bin/gcov-4.6`.
+        #
+        # http://stackoverflow.com/questions/17758126/clang-code-coverage-invalid-output
         my_cflags += --coverage -O0
-        ifeq ($(my_clang),true)
-            # b/17574078
-            # We currently don't have a prebuilt libclang_rt.profile-<ARCH>.a,
-            # which clang is hardcoded to link if --coverage is passed in the
-            # link stage.  For now we manually link libprofile_rt (which is the
-            # name it is built as from external/compiler-rt).
-            #
-            # Note that clang coverage doesn't play nicely with acov out of the
-            # box. Clang apparently generates .gcno files that aren't compatible
-            # with gcov-4.8.  This can be solved by installing gcc-4.6 and
-            # invoking lcov with `--gcov-tool /usr/bin/gcov-4.6`.
-            #
-            # http://stackoverflow.com/questions/17758126/clang-code-coverage-invalid-output
-            my_static_libraries += libprofile_rt
-        else
-            my_ldflags += --coverage
-        endif
+        my_ldflags += --coverage
     endif
 else
     my_native_coverage := false
diff --git a/core/clang/HOST_x86.mk b/core/clang/HOST_x86.mk
index 35cfe60..f14a9c3 100644
--- a/core/clang/HOST_x86.mk
+++ b/core/clang/HOST_x86.mk
@@ -76,3 +76,5 @@
 $(clang_2nd_arch_prefix)CLANG_HOST_GLOBAL_LDFLAGS := \
   $(call $(clang_2nd_arch_prefix)convert-to-host-clang-flags,$($(clang_2nd_arch_prefix)HOST_GLOBAL_LDFLAGS)) \
   $(CLANG_CONFIG_x86_HOST_EXTRA_LDFLAGS)
+
+$(clang_2nd_arch_prefix)HOST_LIBPROFILE_RT := $(LLVM_RTLIB_PATH)/libclang_rt.profile-i686.a
diff --git a/core/clang/HOST_x86_64.mk b/core/clang/HOST_x86_64.mk
index c546715..1211e73 100644
--- a/core/clang/HOST_x86_64.mk
+++ b/core/clang/HOST_x86_64.mk
@@ -76,3 +76,5 @@
 CLANG_HOST_GLOBAL_LDFLAGS := \
   $(call convert-to-host-clang-flags,$(HOST_GLOBAL_LDFLAGS)) \
   $(CLANG_CONFIG_x86_64_HOST_EXTRA_LDFLAGS)
+
+HOST_LIBPROFILE_RT := $(LLVM_RTLIB_PATH)/libclang_rt.profile-x86_64.a
diff --git a/core/clang/TARGET_arm.mk b/core/clang/TARGET_arm.mk
index 993755f..6f6d624 100644
--- a/core/clang/TARGET_arm.mk
+++ b/core/clang/TARGET_arm.mk
@@ -64,3 +64,5 @@
 $(clang_2nd_arch_prefix)RS_TRIPLE := armv7-none-linux-gnueabi
 $(clang_2nd_arch_prefix)RS_TRIPLE_CFLAGS :=
 $(clang_2nd_arch_prefix)RS_COMPAT_TRIPLE := armv7-none-linux-gnueabi
+
+$(clang_2nd_arch_prefix)TARGET_LIBPROFILE_RT := $(LLVM_RTLIB_PATH)/libclang_rt.profile-arm-android.a
diff --git a/core/clang/TARGET_arm64.mk b/core/clang/TARGET_arm64.mk
index ba6e5f1..b67d458 100644
--- a/core/clang/TARGET_arm64.mk
+++ b/core/clang/TARGET_arm64.mk
@@ -62,3 +62,5 @@
 RS_TRIPLE := aarch64-linux-android
 RS_TRIPLE_CFLAGS :=
 RS_COMPAT_TRIPLE := aarch64-linux-android
+
+TARGET_LIBPROFILE_RT := $(LLVM_RTLIB_PATH)/libclang_rt.profile-aarch64-android.a
diff --git a/core/clang/TARGET_mips.mk b/core/clang/TARGET_mips.mk
index 2360181..19bbaf2 100644
--- a/core/clang/TARGET_mips.mk
+++ b/core/clang/TARGET_mips.mk
@@ -63,3 +63,5 @@
 $(clang_2nd_arch_prefix)RS_TRIPLE := armv7-none-linux-gnueabi
 $(clang_2nd_arch_prefix)RS_TRIPLE_CFLAGS :=
 RS_COMPAT_TRIPLE := mipsel-linux-android
+
+$(clang_2nd_arch_prefix)TARGET_LIBPROFILE_RT := $(LLVM_RTLIB_PATH)/libclang_rt.profile-mipsel-android.a
diff --git a/core/clang/TARGET_mips64.mk b/core/clang/TARGET_mips64.mk
index 742be4b..104fb70 100644
--- a/core/clang/TARGET_mips64.mk
+++ b/core/clang/TARGET_mips64.mk
@@ -62,3 +62,5 @@
 RS_TRIPLE := aarch64-linux-android
 RS_TRIPLE_CFLAGS :=
 RS_COMPAT_TRIPLE := mips64el-linux-android
+
+TARGET_LIBPROFILE_RT := $(LLVM_RTLIB_PATH)/libclang_rt.profile-mips64el-android.a
diff --git a/core/clang/TARGET_x86.mk b/core/clang/TARGET_x86.mk
index 3ba34ae..4e9e8be 100644
--- a/core/clang/TARGET_x86.mk
+++ b/core/clang/TARGET_x86.mk
@@ -72,3 +72,5 @@
 $(clang_2nd_arch_prefix)RS_TRIPLE := armv7-none-linux-gnueabi
 $(clang_2nd_arch_prefix)RS_TRIPLE_CFLAGS := -D__i386__
 $(clang_2nd_arch_prefix)RS_COMPAT_TRIPLE := i686-linux-android
+
+$(clang_2nd_arch_prefix)TARGET_LIBPROFILE_RT := $(LLVM_RTLIB_PATH)/libclang_rt.profile-i686-android.a
diff --git a/core/clang/TARGET_x86_64.mk b/core/clang/TARGET_x86_64.mk
index 9f8e8b0..e44382d 100644
--- a/core/clang/TARGET_x86_64.mk
+++ b/core/clang/TARGET_x86_64.mk
@@ -62,3 +62,5 @@
 RS_TRIPLE := aarch64-linux-android
 RS_TRIPLE_CFLAGS := -D__x86_64__
 RS_COMPAT_TRIPLE := x86_64-linux-android
+
+TARGET_LIBPROFILE_RT := $(LLVM_RTLIB_PATH)/libclang_rt.profile-x86_64-android.a
diff --git a/core/clang/config.mk b/core/clang/config.mk
index 60889e7..13a5ba1 100644
--- a/core/clang/config.mk
+++ b/core/clang/config.mk
@@ -8,6 +8,7 @@
 
 LLVM_PREBUILTS_VERSION := 3.6
 LLVM_PREBUILTS_PATH := prebuilts/clang/$(BUILD_OS)-x86/host/$(LLVM_PREBUILTS_VERSION)/bin
+LLVM_RTLIB_PATH := $(LLVM_PREBUILTS_PATH)/../lib/clang/$(LLVM_PREBUILTS_VERSION)/lib/linux/
 
 CLANG := $(LLVM_PREBUILTS_PATH)/clang$(BUILD_EXECUTABLE_SUFFIX)
 CLANG_CXX := $(LLVM_PREBUILTS_PATH)/clang++$(BUILD_EXECUTABLE_SUFFIX)
@@ -67,14 +68,18 @@
   -funswitch-loops \
   -Wmaybe-uninitialized \
   -Wno-error=maybe-uninitialized \
+  -Wno-error=unused-but-set-parameter \
+  -Wno-error=unused-but-set-variable \
   -Wno-free-nonheap-object \
   -Wno-literal-suffix \
   -Wno-maybe-uninitialized \
   -Wno-old-style-declaration \
   -Wno-psabi \
-  -Wno-unused-but-set-variable \
   -Wno-unused-but-set-parameter \
-  -Wno-unused-local-typedefs
+  -Wno-unused-but-set-variable \
+  -Wno-unused-local-typedefs \
+  -Wunused-but-set-parameter \
+  -Wunused-but-set-variable
 
 # Clang flags for all host rules
 CLANG_CONFIG_HOST_EXTRA_ASFLAGS :=
diff --git a/core/combo/HOST_linux-x86.mk b/core/combo/HOST_linux-x86.mk
index 93a1287..5f62400 100644
--- a/core/combo/HOST_linux-x86.mk
+++ b/core/combo/HOST_linux-x86.mk
@@ -49,7 +49,6 @@
 
 $(combo_2nd_arch_prefix)HOST_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined
 
-
 ############################################################
 ## Macros after this line are shared by the 64-bit config.
 
diff --git a/core/definitions.mk b/core/definitions.mk
index c601d86..25f667f 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -1289,7 +1289,7 @@
 @echo "target StaticLib: $(PRIVATE_MODULE) ($@)"
 $(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_AR) \
     $($(PRIVATE_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_ARFLAGS) \
-    $(PRIVATE_ARFLAGS) $@,$(filter %.o, $^))
+    $(PRIVATE_ARFLAGS) $@,$(PRIVATE_ALL_OBJECTS))
 endef
 
 ###########################################################
@@ -1338,7 +1338,7 @@
 @echo "host StaticLib: $(PRIVATE_MODULE) ($@)"
 $(call split-long-arguments,$($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_AR) \
     $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_GLOBAL_ARFLAGS) \
-    $(PRIVATE_ARFLAGS) $@,$(filter %.o, $^))
+    $(PRIVATE_ARFLAGS) $@,$(PRIVATE_ALL_OBJECTS))
 endef
 
 
@@ -1367,6 +1367,7 @@
 	$(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
 	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
 	$(if $(filter true,$(NATIVE_COVERAGE)),-lgcov) \
+	$(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_HOST_LIBPROFILE_RT)) \
 	$(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
 	-o $@ \
 	$(PRIVATE_LDLIBS)
@@ -1405,6 +1406,7 @@
 	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
 	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
 	$(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBGCOV)) \
+	$(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBPROFILE_RT)) \
 	$(PRIVATE_TARGET_LIBATOMIC) \
 	$(PRIVATE_TARGET_LIBGCC) \
 	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
@@ -1468,6 +1470,7 @@
 	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
 	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
 	$(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBGCOV)) \
+	$(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBPROFILE_RT)) \
 	$(PRIVATE_TARGET_LIBATOMIC) \
 	$(PRIVATE_TARGET_LIBGCC) \
 	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
@@ -1513,8 +1516,9 @@
 	-Wl,--start-group \
 	$(call normalize-target-libraries,$(filter %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
 	$(call normalize-target-libraries,$(filter %libc_nomalloc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
-	$(PRIVATE_TARGET_LIBATOMIC) \
 	$(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBGCOV)) \
+	$(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_TARGET_LIBPROFILE_RT)) \
+	$(PRIVATE_TARGET_LIBATOMIC) \
 	$(call normalize-target-libraries,$(filter %libcompiler_rt.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
 	$(PRIVATE_TARGET_LIBGCC) \
 	-Wl,--end-group \
@@ -1552,6 +1556,7 @@
 	$(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
 	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
 	$(if $(filter true,$(NATIVE_COVERAGE)),-lgcov) \
+	$(if $(filter true,$(NATIVE_COVERAGE)),$(PRIVATE_HOST_LIBPROFILE_RT)) \
 	$(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
 	-Wl,-rpath-link=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_INTERMEDIATE_LIBRARIES) \
 	-Wl,-rpath,\$$ORIGIN/../$(notdir $($(PRIVATE_2ND_ARCH_VAR_PREFIX)HOST_OUT_SHARED_LIBRARIES)) \
diff --git a/core/executable_internal.mk b/core/executable_internal.mk
index ebb6867..2684d51 100644
--- a/core/executable_internal.mk
+++ b/core/executable_internal.mk
@@ -35,6 +35,7 @@
 
 # Define PRIVATE_ variables from global vars
 my_target_global_ld_dirs := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_LD_DIRS)
+my_target_libprofile_rt := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_LIBPROFILE_RT)
 my_target_libgcov := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_LIBGCOV)
 my_target_libgcc := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_LIBGCC)
 my_target_libatomic := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_LIBATOMIC)
@@ -55,6 +56,7 @@
 endif
 $(linked_module): PRIVATE_TARGET_GLOBAL_LD_DIRS := $(my_target_global_ld_dirs)
 $(linked_module): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(my_target_global_ldflags)
+$(linked_module): PRIVATE_TARGET_LIBPROFILE_RT := $(my_target_libprofile_rt)
 $(linked_module): PRIVATE_TARGET_LIBGCOV := $(my_target_libgcov)
 $(linked_module): PRIVATE_TARGET_LIBGCC := $(my_target_libgcc)
 $(linked_module): PRIVATE_TARGET_LIBATOMIC := $(my_target_libatomic)
diff --git a/core/host_executable_internal.mk b/core/host_executable_internal.mk
index ffb35d2..0c0ac3d 100644
--- a/core/host_executable_internal.mk
+++ b/core/host_executable_internal.mk
@@ -27,6 +27,9 @@
 
 include $(BUILD_SYSTEM)/binary.mk
 
+my_host_libprofile_rt := $($(LOCAL_2ND_ARCH_VAR_PREFIX)HOST_LIBPROFILE_RT)
+$(LOCAL_BUILT_MODULE): PRIVATE_HOST_LIBPROFILE_RT := $(my_host_libprofile_rt)
+
 $(LOCAL_BUILT_MODULE): $(all_objects) $(all_libraries)
 	$(transform-host-o-to-executable)
 
diff --git a/core/host_shared_library_internal.mk b/core/host_shared_library_internal.mk
index f1b3311..645098a 100644
--- a/core/host_shared_library_internal.mk
+++ b/core/host_shared_library_internal.mk
@@ -40,6 +40,9 @@
 
 include $(BUILD_SYSTEM)/binary.mk
 
+my_host_libprofile_rt := $($(LOCAL_2ND_ARCH_VAR_PREFIX)HOST_LIBPROFILE_RT)
+$(LOCAL_BUILD_MODULE): PRIVATE_HOST_LIBPROFILE_RT := $(my_host_libprofile_rt)
+
 $(LOCAL_BUILT_MODULE): \
         $(all_objects) \
         $(all_libraries) \
diff --git a/core/shared_library_internal.mk b/core/shared_library_internal.mk
index 1fda794..2487fbb0 100644
--- a/core/shared_library_internal.mk
+++ b/core/shared_library_internal.mk
@@ -40,6 +40,7 @@
 
 # Define PRIVATE_ variables from global vars
 my_target_global_ld_dirs := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_LD_DIRS)
+my_target_libprofile_rt := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_LIBPROFILE_RT)
 my_target_libgcov := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_LIBGCOV)
 my_target_libgcc := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_LIBGCC)
 my_target_libatomic := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_LIBATOMIC)
@@ -58,6 +59,7 @@
 endif
 $(linked_module): PRIVATE_TARGET_GLOBAL_LD_DIRS := $(my_target_global_ld_dirs)
 $(linked_module): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(my_target_global_ldflags)
+$(linked_module): PRIVATE_TARGET_LIBPROFILE_RT := $(my_target_libprofile_rt)
 $(linked_module): PRIVATE_TARGET_LIBGCOV := $(my_target_libgcov)
 $(linked_module): PRIVATE_TARGET_LIBGCC := $(my_target_libgcc)
 $(linked_module): PRIVATE_TARGET_LIBATOMIC := $(my_target_libatomic)
diff --git a/tools/fs_config/Android.mk b/tools/fs_config/Android.mk
index 02deabb..984e5b0 100644
--- a/tools/fs_config/Android.mk
+++ b/tools/fs_config/Android.mk
@@ -17,7 +17,8 @@
 
 LOCAL_SRC_FILES := fs_config.c
 LOCAL_MODULE := fs_config
-LOCAL_STATIC_LIBRARIES := libselinux
+LOCAL_STATIC_LIBRARIES := libcutils libselinux
 LOCAL_FORCE_STATIC_EXECUTABLE := true
+LOCAL_CFLAGS := -Werror
 
 include $(BUILD_HOST_EXECUTABLE)
diff --git a/tools/fs_get_stats/Android.mk b/tools/fs_get_stats/Android.mk
index c9b4a05..dc5dff9 100644
--- a/tools/fs_get_stats/Android.mk
+++ b/tools/fs_get_stats/Android.mk
@@ -6,4 +6,6 @@
 
 LOCAL_MODULE := fs_get_stats
 
+LOCAL_SHARED_LIBRARIES := libcutils
+
 include $(BUILD_HOST_EXECUTABLE)
diff --git a/tools/releasetools/build_image.py b/tools/releasetools/build_image.py
index 4e78acb..9f8a8ec 100755
--- a/tools/releasetools/build_image.py
+++ b/tools/releasetools/build_image.py
@@ -231,11 +231,14 @@
   fs_type = prop_dict.get("fs_type", "")
   run_fsck = False
 
+  fs_spans_partition = True
+  if fs_type.startswith("squash"):
+      fs_spans_partition = False
+
   is_verity_partition = "verity_block_device" in prop_dict
   verity_supported = prop_dict.get("verity") == "true"
-  # adjust the partition size to make room for the hashes if this is to be
-  # verified
-  if verity_supported and is_verity_partition:
+  # adjust the partition size to make room for the hashes if this is to be verified
+  if verity_supported and is_verity_partition and fs_spans_partition:
     partition_size = int(prop_dict.get("partition_size"))
     adjusted_size = AdjustPartitionSizeForVerity(partition_size)
     if not adjusted_size:
@@ -301,6 +304,20 @@
   if exit_code != 0:
     return False
 
+  if not fs_spans_partition:
+    mount_point = prop_dict.get("mount_point")
+    partition_size = int(prop_dict.get("partition_size"))
+    image_size = os.stat(out_file).st_size
+    if image_size > partition_size:
+        print "Error: %s image size of %d is larger than partition size of %d" % (mount_point, image_size, partition_size)
+        return False
+    if verity_supported and is_verity_partition:
+        if 2 * image_size - AdjustPartitionSizeForVerity(image_size) > partition_size:
+            print "Error: No more room on %s to fit verity data" % mount_point
+            return False
+    prop_dict["original_partition_size"] = prop_dict["partition_size"]
+    prop_dict["partition_size"] = str(image_size)
+
   # create the verified image if this is to be verified
   if verity_supported and is_verity_partition:
     if not MakeVerityEnabledImage(out_file, prop_dict):