summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill McVicker <willmcvicker@google.com>2024-04-30 15:21:22 -0700
committerWill McVicker <willmcvicker@google.com>2024-04-30 15:27:46 -0700
commit0f8316892f57713ab5f7970aaeb74d386b0191de (patch)
treef5b53d90d0f4c02a76b82d2e62acac2f280db0cd
parent10bee1bdd695ae891e0960adb704e55ecb3e6965 (diff)
downloadextras-0f8316892f57713ab5f7970aaeb74d386b0191de.tar.gz
tools/check_elf_alignment.sh: Add zip alignment check
If an APK is passed in, then check the zipalignment as well to see if it's 16K aligned. This will help cover both requirements -- zipalignment and ELF alignment. Also, add a print message after checking ELF alignment to indicate that it was successful. This helps indicate success when there are no shared libraries in the APK. Bug: 337895632 Change-Id: I2578dba77e13570aa5b880f950058cfcd939857f
-rwxr-xr-xtools/check_elf_alignment.sh26
1 files changed, 26 insertions, 0 deletions
diff --git a/tools/check_elf_alignment.sh b/tools/check_elf_alignment.sh
index da1f0b3f..ba82eb7a 100755
--- a/tools/check_elf_alignment.sh
+++ b/tools/check_elf_alignment.sh
@@ -42,6 +42,19 @@ fi
if [[ ${dir} == *.apk ]]; then
trap 'cleanup_trap' EXIT
+
+ if { zipalign --help 2>&1 | grep -q "\-P <pagesize_kb>"; }; then
+ echo "=== APK zip-alignment ==="
+ zipalign -v -c -P 16 4 ${dir} | egrep 'lib/arm64-v8a|lib/x86_64|Verification'
+ echo "========================="
+ else
+ echo "NOTICE: Zip alignment check requires build-tools version 35.0.0-rc3 or higher."
+ echo " You can install the latest build-tools by running the below command"
+ echo " and updating your \$PATH:"
+ echo
+ echo " sdkmanager \"build-tools;35.0.0-rc3\""
+ fi
+
dir_filename=$(basename ${dir})
tmp=$(mktemp -d -t ${dir_filename%.apk}_out_XXXXX)
unzip ${dir} lib/arm64-v8a/* lib/x86_64/* -d ${tmp} >/dev/null 2>&1
@@ -52,6 +65,11 @@ RED="\e[31m"
GREEN="\e[32m"
ENDCOLOR="\e[0m"
+unaligned_libs=()
+
+echo
+echo "=== ELF alignment ==="
+
matches="$(find ${dir} -name "*.so" -type f)"
IFS=$'\n'
for match in $matches; do
@@ -60,5 +78,13 @@ for match in $matches; do
echo -e "${match}: ${GREEN}ALIGNED${ENDCOLOR} ($res)"
else
echo -e "${match}: ${RED}UNALIGNED${ENDCOLOR} ($res)"
+ unaligned_libs+=(${match})
fi
done
+
+if [ ${#unaligned_libs[@]} -gt 0 ]; then
+ echo -e "${RED}Found ${#unaligned_libs[@]} unaligned libs${ENDCOLOR}"
+elif [ -n "${dir_filename}" ]; then
+ echo -e "ELF Verification Successful"
+fi
+echo "====================="