gn2bp: Support MTE in arm64 to fix build error
Test: lunch aosp_arm64 && m cronet_aml_components_cronet_android_cronet
Change-Id: I73b92b96175689f649e0bba04db0fbb1f38d0c5e
diff --git a/tools/gn2bp/Android.bp.swp b/tools/gn2bp/Android.bp.swp
index 60caa1d..50bb9b9 100644
--- a/tools/gn2bp/Android.bp.swp
+++ b/tools/gn2bp/Android.bp.swp
@@ -641,6 +641,7 @@
"-DANDROID",
"-DANDROID_NDK_VERSION_ROLL=r23_1",
"-DHAVE_SYS_UIO_H",
+ "-march=armv8-a+memtag",
],
local_include_dirs: [
"third_party/android_ndk/sources/android/cpufeatures/",
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index 000faf5..addcaac 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -903,6 +903,12 @@
# TODO: set_module_xxx is confusing, apply similar function to module and target in better way.
for arch_name, arch in target.arch.items():
set_module_flags(module.target[arch_name], arch.cflags, arch.defines)
+ # -Xclang -target-feature -Xclang +mte are used to enable MTE (Memory Tagging Extensions).
+ # Flags which does not start with '-' could not be in the cflags so enabling MTE by
+ # -march and -mcpu Feature Modifiers. MTE is only available on arm64. This is needed for
+ # building //base/allocator/partition_allocator:partition_alloc for arm64.
+ if '+mte' in arch.cflags and arch_name == 'android_arm64':
+ module.target[arch_name].cflags.add('-march=armv8-a+memtag')
set_module_include_dirs(module.target[arch_name], arch.cflags, arch.include_dirs)
if module.is_compiled():