Upgrade xz-embedded to d89ad8130128d71c773f5e50e356562a506f843e am: 9ecffe1d16 am: 1ad65adab5 am: e472aa9e0f am: 61719849ac am: eb3a388512

Original change: https://android-review.googlesource.com/c/platform/external/xz-embedded/+/2646463

Change-Id: I92e5bba7d0f5f3f07418f4abf4e73baa91486033
Signed-off-by: Automerger Merge Worker <[email protected]>
diff --git a/METADATA b/METADATA
index 72800f8..46bfe82 100644
--- a/METADATA
+++ b/METADATA
@@ -1,3 +1,7 @@
+# This project was upgraded with external_updater.
+# Usage: tools/external_updater/updater.sh update xz-embedded
+# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md
+
 name: "xz-embedded"
 description: "XZ Embedded"
 third_party {
@@ -5,11 +9,11 @@
     type: GIT
     value: "https://git.tukaani.org/xz-embedded.git"
   }
-  version: "3f438e15109229bb14ab45f285f4bff5412a9542"
+  version: "d89ad8130128d71c773f5e50e356562a506f843e"
   license_type: UNENCUMBERED
   last_upgrade_date {
-    year: 2021
-    month: 10
-    day: 11
+    year: 2023
+    month: 6
+    day: 30
   }
 }
diff --git a/README b/README
index c8ca09c..32c4625 100644
--- a/README
+++ b/README
@@ -35,9 +35,10 @@
         make -C /path/to/kernel/source \
                 KCPPFLAGS=-I"$(pwd)/../../include" M="$(pwd)" \
                 CONFIG_XZ_DEC=m CONFIG_XZ_DEC_TEST=m CONFIG_XZ_DEC_BCJ=y \
-                CONFIG_XZ_DEC_X86=y CONFIG_XZ_DEC_POWERPC=y \
-                CONFIG_XZ_DEC_IA64=y CONFIG_XZ_DEC_ARM=y \
-                CONFIG_XZ_DEC_ARMTHUMB=y CONFIG_XZ_DEC_SPARC=y
+                CONFIG_XZ_DEC_X86=y CONFIG_XZ_DEC_ARM=y \
+                CONFIG_XZ_DEC_ARMTHUMB=y CONFIG_XZ_DEC_ARM64=y \
+                CONFIG_XZ_DEC_POWERPC=y CONFIG_XZ_DEC_IA64=y \
+                CONFIG_XZ_DEC_SPARC=y
 
     If you want only one or a few of the BCJ filters, omit the appropriate
     variables. CONFIG_XZ_DEC_BCJ=y is always required to build the support
diff --git a/README.version b/README.version
deleted file mode 100644
index a9aaf07..0000000
--- a/README.version
+++ /dev/null
@@ -1,2 +0,0 @@
-URL: https://git.tukaani.org/?p=xz-embedded.git
-Version: 79b68de5657beecfad575578a7181cf6fca869cb
diff --git a/linux/lib/xz/Kconfig b/linux/lib/xz/Kconfig
index 3e58caf..c993dda 100644
--- a/linux/lib/xz/Kconfig
+++ b/linux/lib/xz/Kconfig
@@ -9,33 +9,38 @@
 if XZ_DEC
 
 config XZ_DEC_X86
-	bool "x86 BCJ filter decoder"
-	default y if X86
+	bool "x86 BCJ filter decoder" if EXPERT
+	default y
 	select XZ_DEC_BCJ
 
 config XZ_DEC_POWERPC
-	bool "PowerPC BCJ filter decoder"
-	default y if PPC
+	bool "PowerPC BCJ filter decoder" if EXPERT
+	default y
 	select XZ_DEC_BCJ
 
 config XZ_DEC_IA64
-	bool "IA-64 BCJ filter decoder"
-	default y if IA64
+	bool "IA-64 BCJ filter decoder" if EXPERT
+	default y
 	select XZ_DEC_BCJ
 
 config XZ_DEC_ARM
-	bool "ARM BCJ filter decoder"
-	default y if ARM
+	bool "ARM BCJ filter decoder" if EXPERT
+	default y
 	select XZ_DEC_BCJ
 
 config XZ_DEC_ARMTHUMB
-	bool "ARM-Thumb BCJ filter decoder"
-	default y if (ARM && ARM_THUMB)
+	bool "ARM-Thumb BCJ filter decoder" if EXPERT
+	default y
+	select XZ_DEC_BCJ
+
+config XZ_DEC_ARM64
+	bool "ARM64 BCJ filter decoder" if EXPERT
+	default y
 	select XZ_DEC_BCJ
 
 config XZ_DEC_SPARC
-	bool "SPARC BCJ filter decoder"
-	default y if SPARC
+	bool "SPARC BCJ filter decoder" if EXPERT
+	default y
 	select XZ_DEC_BCJ
 
 config XZ_DEC_MICROLZMA
diff --git a/linux/lib/xz/xz_dec_bcj.c b/linux/lib/xz/xz_dec_bcj.c
index ef449e9..56c02e9 100644
--- a/linux/lib/xz/xz_dec_bcj.c
+++ b/linux/lib/xz/xz_dec_bcj.c
@@ -24,7 +24,8 @@
 		BCJ_IA64 = 6,       /* Big or little endian */
 		BCJ_ARM = 7,        /* Little endian only */
 		BCJ_ARMTHUMB = 8,   /* Little endian only */
-		BCJ_SPARC = 9       /* Big or little endian */
+		BCJ_SPARC = 9,      /* Big or little endian */
+		BCJ_ARM64 = 10      /* AArch64 */
 	} type;
 
 	/*
@@ -334,6 +335,45 @@
 }
 #endif
 
+#ifdef XZ_DEC_ARM64
+static size_t bcj_arm64(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
+{
+	size_t i;
+	uint32_t instr;
+	uint32_t addr;
+
+	for (i = 0; i + 4 <= size; i += 4) {
+		instr = get_unaligned_le32(buf + i);
+
+		if ((instr >> 26) == 0x25) {
+			/* BL instruction */
+			addr = instr - ((s->pos + (uint32_t)i) >> 2);
+			instr = 0x94000000 | (addr & 0x03FFFFFF);
+			put_unaligned_le32(instr, buf + i);
+
+		} else if ((instr & 0x9F000000) == 0x90000000) {
+			/* ADRP instruction */
+			addr = ((instr >> 29) & 3) | ((instr >> 3) & 0x1FFFFC);
+
+			/* Only convert values in the range +/-512 MiB. */
+			if ((addr + 0x020000) & 0x1C0000)
+				continue;
+
+			addr -= (s->pos + (uint32_t)i) >> 12;
+
+			instr &= 0x9000001F;
+			instr |= (addr & 3) << 29;
+			instr |= (addr & 0x03FFFC) << 3;
+			instr |= (0U - (addr & 0x020000)) & 0xE00000;
+
+			put_unaligned_le32(instr, buf + i);
+		}
+	}
+
+	return i;
+}
+#endif
+
 /*
  * Apply the selected BCJ filter. Update *pos and s->pos to match the amount
  * of data that got filtered.
@@ -381,6 +421,11 @@
 		filtered = bcj_sparc(s, buf, size);
 		break;
 #endif
+#ifdef XZ_DEC_ARM64
+	case BCJ_ARM64:
+		filtered = bcj_arm64(s, buf, size);
+		break;
+#endif
 	default:
 		/* Never reached but silence compiler warnings. */
 		filtered = 0;
@@ -554,6 +599,9 @@
 #ifdef XZ_DEC_SPARC
 	case BCJ_SPARC:
 #endif
+#ifdef XZ_DEC_ARM64
+	case BCJ_ARM64:
+#endif
 		break;
 
 	default:
diff --git a/linux/lib/xz/xz_private.h b/linux/lib/xz/xz_private.h
index d9fd49b..e3bba7b 100644
--- a/linux/lib/xz/xz_private.h
+++ b/linux/lib/xz/xz_private.h
@@ -37,6 +37,9 @@
 #		ifdef CONFIG_XZ_DEC_SPARC
 #			define XZ_DEC_SPARC
 #		endif
+#		ifdef CONFIG_XZ_DEC_ARM64
+#			define XZ_DEC_ARM64
+#		endif
 #		ifdef CONFIG_XZ_DEC_MICROLZMA
 #			define XZ_DEC_MICROLZMA
 #		endif
diff --git a/userspace/Makefile b/userspace/Makefile
index 1acacf0..b48d30c 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -11,8 +11,8 @@
 # the code is also C99/C11 compatible. With clang you may wish to omit
 # either -std=gnu89 or -pedantic as having both gives quite a few warnings.
 CC = gcc -std=gnu89
-BCJ_CPPFLAGS = -DXZ_DEC_X86 -DXZ_DEC_POWERPC -DXZ_DEC_IA64 \
-		-DXZ_DEC_ARM -DXZ_DEC_ARMTHUMB -DXZ_DEC_SPARC
+BCJ_CPPFLAGS = -DXZ_DEC_X86 -DXZ_DEC_ARM -DXZ_DEC_ARMTHUMB -DXZ_DEC_ARM64 \
+		-DXZ_DEC_POWERPC -DXZ_DEC_IA64 -DXZ_DEC_SPARC
 CPPFLAGS = -DXZ_USE_CRC64 -DXZ_DEC_ANY_CHECK -DXZ_DEC_CONCATENATED
 CFLAGS = -ggdb3 -O2 -pedantic -Wall -Wextra -Wno-long-long
 RM = rm -f
diff --git a/userspace/xz_config.h b/userspace/xz_config.h
index ee590d7..ac1b6c3 100644
--- a/userspace/xz_config.h
+++ b/userspace/xz_config.h
@@ -18,10 +18,11 @@
 
 /* Uncomment as needed to enable BCJ filter decoders. */
 /* #define XZ_DEC_X86 */
-/* #define XZ_DEC_POWERPC */
-/* #define XZ_DEC_IA64 */
 /* #define XZ_DEC_ARM */
 /* #define XZ_DEC_ARMTHUMB */
+/* #define XZ_DEC_ARM64 */
+/* #define XZ_DEC_POWERPC */
+/* #define XZ_DEC_IA64 */
 /* #define XZ_DEC_SPARC */
 
 /*