Merge changes I4c84d194,I696b424e

* changes:
  Combine HOST/TARGET in Test Suite NOTICE.
  Build NOTICE txt file into TestSuite zip package.
diff --git a/core/base_rules.mk b/core/base_rules.mk
index 3f93c2c..abe059b 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -77,6 +77,20 @@
 endif
 _path :=
 
+ifeq ($(LOCAL_HOST_MODULE),true)
+my_image_variant := host
+else ifeq ($(LOCAL_VENDOR_MODULE),true)
+my_image_variant := vendor
+else ifeq ($(LOCAL_OEM_MODULE),true)
+my_image_variant := vendor
+else ifeq ($(LOCAL_ODM_MODULE),true)
+my_image_variant := vendor
+else ifeq ($(LOCAL_PRODUCT_MODULE),true)
+my_image_variant := product
+else
+my_image_variant := core
+endif
+
 # TODO(b/135957588) Remove following workaround
 # LOCAL_PRODUCT_SERVICES_MODULE to LOCAL_PRODUCT_MODULE for all Android.mk
 ifndef LOCAL_PRODUCT_MODULE
diff --git a/core/binary.mk b/core/binary.mk
index be7dc27..0b03f6a 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -64,10 +64,64 @@
 my_export_c_include_deps := $(LOCAL_EXPORT_C_INCLUDE_DEPS)
 my_arflags :=
 
+# Disable clang-tidy if it is not found.
+ifeq ($(PATH_TO_CLANG_TIDY),)
+  my_tidy_enabled := false
+else
+  # If LOCAL_TIDY is not defined, use global WITH_TIDY
+  my_tidy_enabled := $(LOCAL_TIDY)
+  ifeq ($(my_tidy_enabled),)
+    my_tidy_enabled := $(WITH_TIDY)
+  endif
+endif
+
+# my_tidy_checks is empty if clang-tidy is disabled.
+my_tidy_checks :=
+my_tidy_flags :=
+ifneq (,$(filter 1 true,$(my_tidy_enabled)))
+  # Set up global default checks
+  my_tidy_checks := $(WITH_TIDY_CHECKS)
+  ifeq ($(my_tidy_checks),)
+    my_tidy_checks := $(call default_global_tidy_checks,$(LOCAL_PATH))
+  endif
+  # Append local clang-tidy checks.
+  ifneq ($(LOCAL_TIDY_CHECKS),)
+    my_tidy_checks := $(my_tidy_checks),$(LOCAL_TIDY_CHECKS)
+  endif
+  my_tidy_flags := $(strip $(WITH_TIDY_FLAGS) $(LOCAL_TIDY_FLAGS))
+  # If tidy flags are not specified, default to check all header files.
+  ifeq ($(my_tidy_flags),)
+    my_tidy_flags := $(call default_tidy_header_filter,$(LOCAL_PATH))
+  endif
+  # If clang-tidy is not enabled globally, add the -quiet flag.
+  ifeq (,$(filter 1 true,$(WITH_TIDY)))
+    my_tidy_flags += -quiet -extra-arg-before=-fno-caret-diagnostics
+  endif
+
+  ifneq ($(my_tidy_checks),)
+    # We might be using the static analyzer through clang-tidy.
+    # https://bugs.llvm.org/show_bug.cgi?id=32914
+    my_tidy_flags += -extra-arg-before=-D__clang_analyzer__
+
+    # A recent change in clang-tidy (r328258) enabled destructor inlining,
+    # which appears to cause a number of false positives. Until that's
+    # resolved, this turns off the effects of r328258.
+    # https://bugs.llvm.org/show_bug.cgi?id=37459
+    my_tidy_flags += -extra-arg-before=-Xclang
+    my_tidy_flags += -extra-arg-before=-analyzer-config
+    my_tidy_flags += -extra-arg-before=-Xclang
+    my_tidy_flags += -extra-arg-before=c++-temp-dtor-inlining=false
+  endif
+endif
+
+my_tidy_checks := $(subst $(space),,$(my_tidy_checks))
+
 # Configure the pool to use for clang rules.
 # If LOCAL_CC or LOCAL_CXX is set don't use goma or RBE.
+# If clang-tidy is being used, don't use the RBE pool (as clang-tidy runs in
+# the same action, and is not remoted)
 my_pool :=
-ifeq (,$(strip $(my_cc))$(strip $(my_cxx)))
+ifeq (,$(strip $(my_cc))$(strip $(my_cxx))$(strip $(my_tidy_checks)))
   my_pool := $(GOMA_OR_RBE_POOL)
 endif
 
@@ -102,6 +156,8 @@
 my_ndk_sysroot_lib :=
 my_api_level := 10000
 
+my_arch := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
+
 ifneq ($(LOCAL_SDK_VERSION),)
   ifdef LOCAL_IS_HOST_MODULE
     $(error $(LOCAL_PATH): LOCAL_SDK_VERSION cannot be used in host module)
@@ -110,7 +166,6 @@
   # Make sure we've built the NDK.
   my_additional_dependencies += $(SOONG_OUT_DIR)/ndk_base.timestamp
 
-  my_arch := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
   ifneq (,$(filter arm64 x86_64,$(my_arch)))
     my_min_sdk_version := 21
   else
@@ -1060,37 +1115,39 @@
 endif
 
 ###################################################################
+## Convert to sanitized names where they exist.
+## These lists come from sanitizerStaticLibsMap; see
+## build/soong/cc/sanitize.go
+##
+## $(1): list of static dependencies
+## $(2): name of sanitizer (e.g. cfi, hwasan)
+##################################################################
+define use_soong_sanitized_static_libraries
+  $(foreach lib,$(1),$(if $(filter $(lib),\
+      $(SOONG_$(2)_$(my_image_variant)_$(my_arch)_STATIC_LIBRARIES)),\
+      $(lib).$(2),$(lib)))
+endef
+
+###################################################################
 ## When compiling a CFI enabled target, use the .cfi variant of any
 ## static dependencies (where they exist).
 ##################################################################
-define use_soong_cfi_static_libraries
-  $(foreach l,$(1),$(if $(filter $(l),$(SOONG_CFI_STATIC_LIBRARIES)),\
-      $(l).cfi,$(l)))
-endef
-
 ifneq ($(filter cfi,$(my_sanitize)),)
-  my_whole_static_libraries := $(call use_soong_cfi_static_libraries,\
-    $(my_whole_static_libraries))
-  my_static_libraries := $(call use_soong_cfi_static_libraries,\
-    $(my_static_libraries))
+  my_whole_static_libraries := $(call use_soong_sanitized_static_libraries,\
+    $(my_whole_static_libraries),cfi)
+  my_static_libraries := $(call use_soong_sanitized_static_libraries,\
+    $(my_static_libraries),cfi)
 endif
 
-ifneq ($(LOCAL_USE_VNDK),)
-  my_soong_hwasan_static_libraries := $(SOONG_HWASAN_VENDOR_STATIC_LIBRARIES)
-else
-  my_soong_hwasan_static_libraries = $(SOONG_HWASAN_STATIC_LIBRARIES)
-endif
-
-define use_soong_hwasan_static_libraries
-  $(foreach l,$(1),$(if $(filter $(l),$(my_soong_hwasan_static_libraries)),\
-      $(l).hwasan,$(l)))
-endef
-
+###################################################################
+## When compiling a hwasan enabled target, use the .hwasan variant
+## of any static dependencies (where they exist).
+##################################################################
 ifneq ($(filter hwaddress,$(my_sanitize)),)
-  my_whole_static_libraries := $(call use_soong_hwasan_static_libraries,\
-    $(my_whole_static_libraries))
-  my_static_libraries := $(call use_soong_hwasan_static_libraries,\
-    $(my_static_libraries))
+  my_whole_static_libraries := $(call use_soong_sanitized_static_libraries,\
+    $(my_whole_static_libraries),hwasan)
+  my_static_libraries := $(call use_soong_sanitized_static_libraries,\
+    $(my_static_libraries),hwasan)
 endif
 
 ###########################################################
@@ -1480,61 +1537,10 @@
   endif
 endif
 
-# Disable clang-tidy if it is not found.
-ifeq ($(PATH_TO_CLANG_TIDY),)
-  my_tidy_enabled := false
-else
-  # If LOCAL_TIDY is not defined, use global WITH_TIDY
-  my_tidy_enabled := $(LOCAL_TIDY)
-  ifeq ($(my_tidy_enabled),)
-    my_tidy_enabled := $(WITH_TIDY)
-  endif
-endif
-
-# my_tidy_checks is empty if clang-tidy is disabled.
-my_tidy_checks :=
-my_tidy_flags :=
-ifneq (,$(filter 1 true,$(my_tidy_enabled)))
-  tidy_only: $(cpp_objects) $(c_objects) $(gen_c_objects) $(gen_cpp_objects)
-  # Set up global default checks
-  my_tidy_checks := $(WITH_TIDY_CHECKS)
-  ifeq ($(my_tidy_checks),)
-    my_tidy_checks := $(call default_global_tidy_checks,$(LOCAL_PATH))
-  endif
-  # Append local clang-tidy checks.
-  ifneq ($(LOCAL_TIDY_CHECKS),)
-    my_tidy_checks := $(my_tidy_checks),$(LOCAL_TIDY_CHECKS)
-  endif
-  my_tidy_flags := $(strip $(WITH_TIDY_FLAGS) $(LOCAL_TIDY_FLAGS))
-  # If tidy flags are not specified, default to check all header files.
-  ifeq ($(my_tidy_flags),)
-    my_tidy_flags := $(call default_tidy_header_filter,$(LOCAL_PATH))
-  endif
-  # If clang-tidy is not enabled globally, add the -quiet flag.
-  ifeq (,$(filter 1 true,$(WITH_TIDY)))
-    my_tidy_flags += -quiet -extra-arg-before=-fno-caret-diagnostics
-  endif
-
-  ifneq ($(my_tidy_checks),)
-    # We might be using the static analyzer through clang-tidy.
-    # https://bugs.llvm.org/show_bug.cgi?id=32914
-    my_tidy_flags += -extra-arg-before=-D__clang_analyzer__
-
-    # A recent change in clang-tidy (r328258) enabled destructor inlining,
-    # which appears to cause a number of false positives. Until that's
-    # resolved, this turns off the effects of r328258.
-    # https://bugs.llvm.org/show_bug.cgi?id=37459
-    my_tidy_flags += -extra-arg-before=-Xclang
-    my_tidy_flags += -extra-arg-before=-analyzer-config
-    my_tidy_flags += -extra-arg-before=-Xclang
-    my_tidy_flags += -extra-arg-before=c++-temp-dtor-inlining=false
-  endif
-endif
-
-my_tidy_checks := $(subst $(space),,$(my_tidy_checks))
-
-# Add dependency of clang-tidy and clang-tidy.sh
 ifneq ($(my_tidy_checks),)
+  tidy_only: $(cpp_objects) $(c_objects) $(gen_c_objects) $(gen_cpp_objects)
+
+  # Add dependency of clang-tidy and clang-tidy.sh
   $(cpp_objects): $(intermediates)/%.o: $(PATH_TO_CLANG_TIDY)
   $(c_objects): $(intermediates)/%.o: $(PATH_TO_CLANG_TIDY)
   $(gen_cpp_objects): $(intermediates)/%.o: $(PATH_TO_CLANG_TIDY)
diff --git a/core/board_config.mk b/core/board_config.mk
index d4fe618..391e280 100644
--- a/core/board_config.mk
+++ b/core/board_config.mk
@@ -91,6 +91,11 @@
 
 _board_strip_readonly_list += $(_dynamic_partitions_var_list)
 
+# Kernel related variables
+_board_strip_readonly_list += \
+  BOARD_KERNEL_BINARIES \
+  BOARD_KERNEL_MODULE_INTERFACE_VERSIONS \
+
 _build_broken_var_list := \
   BUILD_BROKEN_DUP_RULES \
   BUILD_BROKEN_ELF_PREBUILT_PRODUCT_COPY_FILES \
diff --git a/core/main.mk b/core/main.mk
index 4578d90..ab9962a 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -213,6 +213,9 @@
 ADDITIONAL_SYSTEM_PROPERTIES += persist.debug.dalvik.vm.core_platform_api_policy=just-warn
 endif
 
+# Define ro.sanitize.<name> properties for all global sanitizers.
+ADDITIONAL_SYSTEM_PROPERTIES += $(foreach s,$(SANITIZE_TARGET),ro.sanitize.$(s)=true)
+
 # Sets the default value of ro.postinstall.fstab.prefix to /system.
 # Device board config should override the value to /product when needed by:
 #
diff --git a/core/soong_config.mk b/core/soong_config.mk
index 98ab07d..01b355e 100644
--- a/core/soong_config.mk
+++ b/core/soong_config.mk
@@ -217,6 +217,7 @@
 $(call add_json_bool, BoardUsesRecoveryAsBoot, $(BOARD_USES_RECOVERY_AS_BOOT))
 
 $(call add_json_list, BoardKernelBinaries, $(BOARD_KERNEL_BINARIES))
+$(call add_json_list, BoardKernelModuleInterfaceVersions, $(BOARD_KERNEL_MODULE_INTERFACE_VERSIONS))
 
 $(call json_end)
 
diff --git a/target/board/BoardConfigGsiCommon.mk b/target/board/BoardConfigGsiCommon.mk
index d0aeb1c..9d55f42 100644
--- a/target/board/BoardConfigGsiCommon.mk
+++ b/target/board/BoardConfigGsiCommon.mk
@@ -33,20 +33,14 @@
 #   updating the last seen rollback index in the tamper-evident storage.
 BOARD_AVB_ROLLBACK_INDEX := 0
 
-ifndef BUILDING_GSI
 # Enable AVB chained partition for system.
 # https://android.googlesource.com/platform/external/avb/+/master/README.md
 BOARD_AVB_SYSTEM_KEY_PATH := external/avb/test/data/testkey_rsa2048.pem
 BOARD_AVB_SYSTEM_ALGORITHM := SHA256_RSA2048
 BOARD_AVB_SYSTEM_ROLLBACK_INDEX := $(PLATFORM_SECURITY_PATCH_TIMESTAMP)
 BOARD_AVB_SYSTEM_ROLLBACK_INDEX_LOCATION := 1
-else
-# Enable vbmeta_system on GSI targets
-BOARD_AVB_VBMETA_SYSTEM := system
-BOARD_AVB_VBMETA_SYSTEM_KEY_PATH := external/avb/test/data/testkey_rsa2048.pem
-BOARD_AVB_VBMETA_SYSTEM_ALGORITHM := SHA256_RSA2048
-BOARD_AVB_VBMETA_SYSTEM_ROLLBACK_INDEX := $(PLATFORM_SECURITY_PATCH_TIMESTAMP)
-BOARD_AVB_VBMETA_SYSTEM_ROLLBACK_INDEX_LOCATION := 1
+ifdef BUILDING_GSI
+# super.img spec for GSI targets
 BOARD_SUPER_PARTITION_SIZE := 3229614080
 BOARD_SUPER_PARTITION_GROUPS := gsi_dynamic_partitions
 BOARD_GSI_DYNAMIC_PARTITIONS_PARTITION_LIST := system
diff --git a/target/product/gsi/Android.mk b/target/product/gsi/Android.mk
index c491d4a..6775131 100644
--- a/target/product/gsi/Android.mk
+++ b/target/product/gsi/Android.mk
@@ -211,3 +211,13 @@
 LOCAL_MODULE_RELATIVE_PATH := init
 
 include $(BUILD_PREBUILT)
+
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := init.vndk-nodef.rc
+LOCAL_SRC_FILES := $(LOCAL_MODULE)
+LOCAL_MODULE_CLASS := ETC
+LOCAL_SYSTEM_EXT_MODULE := true
+LOCAL_MODULE_RELATIVE_PATH := init
+
+include $(BUILD_PREBUILT)
diff --git a/target/product/gsi/init.gsi.rc b/target/product/gsi/init.gsi.rc
index c6faba7..f482843 100644
--- a/target/product/gsi/init.gsi.rc
+++ b/target/product/gsi/init.gsi.rc
@@ -1,3 +1,5 @@
 #
 # Android init script for GSI required initialization
 #
+
+import /system/system_ext/etc/init/init.vndk-${ro.vndk.version:-nodef}.rc
diff --git a/target/product/gsi/init.legacy-gsi.rc b/target/product/gsi/init.legacy-gsi.rc
deleted file mode 100644
index 00dd576..0000000
--- a/target/product/gsi/init.legacy-gsi.rc
+++ /dev/null
@@ -1,3 +0,0 @@
-# If ro.vndk.version is not defined, import init.vndk-27.rc.
-import /system/etc/init/gsi/init.vndk-${ro.vndk.version:-27}.rc
-
diff --git a/target/product/gsi/init.vndk-27.rc b/target/product/gsi/init.vndk-27.rc
deleted file mode 100644
index d464a2f..0000000
--- a/target/product/gsi/init.vndk-27.rc
+++ /dev/null
@@ -1,3 +0,0 @@
-on early-init
-    # Set ro.vndk.version to 27 so that O-MR1-VENDOR can run latest GSI.
-    setprop ro.vndk.version 27
diff --git a/target/product/gsi/init.vndk-nodef.rc b/target/product/gsi/init.vndk-nodef.rc
new file mode 100644
index 0000000..efeef11
--- /dev/null
+++ b/target/product/gsi/init.vndk-nodef.rc
@@ -0,0 +1,3 @@
+on early-init
+    # Must define BOARD_VNDK_VERSION
+    exec - root -- /system/bin/reboot bootloader
diff --git a/target/product/gsi_release.mk b/target/product/gsi_release.mk
index 5421ee0..46c956d 100644
--- a/target/product/gsi_release.mk
+++ b/target/product/gsi_release.mk
@@ -49,7 +49,8 @@
 # GSI specific tasks on boot
 PRODUCT_PACKAGES += \
     gsi_skip_mount.cfg \
-    init.gsi.rc
+    init.gsi.rc \
+    init.vndk-nodef.rc \
 
 # Support additional P and Q VNDK packages
 PRODUCT_EXTRA_VNDK_VERSIONS := 28 29
diff --git a/target/product/legacy_gsi_release.mk b/target/product/legacy_gsi_release.mk
index c1646bb..09b96fb 100644
--- a/target/product/legacy_gsi_release.mk
+++ b/target/product/legacy_gsi_release.mk
@@ -16,22 +16,8 @@
 
 include $(SRC_TARGET_DIR)/product/gsi_release.mk
 
-PRODUCT_ARTIFACT_PATH_REQUIREMENT_ALLOWED_LIST += \
-    system/etc/init/init.legacy-gsi.rc \
-    system/etc/init/gsi/init.vndk-27.rc \
-    system/etc/ld.config.vndk_lite.txt \
-
 # Legacy GSI support additional O-MR1 interface
 PRODUCT_EXTRA_VNDK_VERSIONS += 27
 
-# Support for the O-MR1 devices
-PRODUCT_COPY_FILES += \
-    build/make/target/product/gsi/init.legacy-gsi.rc:system/etc/init/init.legacy-gsi.rc \
-    build/make/target/product/gsi/init.vndk-27.rc:system/etc/init/gsi/init.vndk-27.rc
-
-# Namespace configuration file for non-enforcing VNDK
-PRODUCT_PACKAGES += \
-    ld.config.vndk_lite.txt
-
 # Legacy GSI relax the compatible property checking
 PRODUCT_COMPATIBLE_PROPERTY_OVERRIDE := false
diff --git a/tools/check_identical_lib.sh b/tools/check_identical_lib.sh
index c3aa41a..c9f436f 100755
--- a/tools/check_identical_lib.sh
+++ b/tools/check_identical_lib.sh
@@ -26,7 +26,19 @@
 strip_lib ${CORE} ${stripped_core}
 strip_lib ${VENDOR} ${stripped_vendor}
 if ! cmp -s ${stripped_core} ${stripped_vendor}; then
-  echo "VNDK library not in vndkMustUseVendorVariantList but has different core and vendor variant: $(basename ${CORE})"
-  echo "If the two variants need to have different runtime behavior, consider using libvndksupport."
+  echo "ERROR: VNDK library $(basename ${CORE%.so}) has different core and" \
+    "vendor variants! This means that the copy used in the system.img/etc" \
+    "and vendor.img/etc images are different. In order to preserve space on" \
+    "some devices, it is helpful if they are the same. Frequently, " \
+    "libraries are different because they or their dependencies compile" \
+    "things based on the macro '__ANDROID_VNDK__' or they specify custom" \
+    "options under 'target: { vendor: { ... } }'. Here are some possible" \
+    "resolutions:"
+  echo "ERROR: 1). Remove differences, possibly using the libvndksupport" \
+    "function android_is_in_vendor_process in order to turn this into a" \
+    "runtime difference."
+  echo "ERROR: 2). Add the library to the VndkMustUseVendorVariantList" \
+    "variable in build/soong/cc/config/vndk.go, which is used to" \
+    "acknowledge this difference."
   exit 1
 fi