From c7c0e42748673e7570349b573f21f98fd56070b0 Mon Sep 17 00:00:00 2001 From: Justin Yun Date: Tue, 29 Nov 2022 14:01:46 +0900 Subject: [PATCH] Provide a script to update the generated Android.bp modify_bp_for_hwasan.sh updates the generated Android.bp to use hwasan prebuilt libraries. Bug: 234772527 Test: modify_bp_for_hwasan.sh Android.bp arch-arm64-armv8/hwasan modify_bp_for_hwasan.sh Android.bp restore Change-Id: I1443200297119d162b680bd8ddd87a9e4ced2e31 --- vendor_snapshot/modify_bp_for_hwasan.sh | 60 +++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 vendor_snapshot/modify_bp_for_hwasan.sh diff --git a/vendor_snapshot/modify_bp_for_hwasan.sh b/vendor_snapshot/modify_bp_for_hwasan.sh new file mode 100755 index 000000000..80c3d7ae3 --- /dev/null +++ b/vendor_snapshot/modify_bp_for_hwasan.sh @@ -0,0 +1,60 @@ +#!/bin/bash -e +# +# Copyright (C) 2022 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +function usage { + cat < |restore + + Read to update the Android.bp file of + to use the hwasan prebuilt static libraries instead of the cfi libraries. + must be the relative path to the . + If 'restore' is set, it will revert the modification. +EOF + exit 1 +} + +if [[ "$#" != 2 ]]; then + usage +fi + +bp_path="$1" +bp_org_path="$bp_path".original + +if [[ "$2" != "restore" ]]; then + if [[ -f "$bp_org_path" ]]; then + echo Already updated. Try again after restoring the bp file with the \"restore\" option. + exit 1 + fi + hwasan_dir="${2%/}" + modules=`ls $(dirname "$bp_path")/"$hwasan_dir"/*.a | xargs -n 1 basename -s .a` + + cp $bp_path $bp_org_path + for module in $modules; do + echo Modifying $module... + bpmodify -w -m $module -move-property -property arch.arm64.cfi -new-location hwasan $bp_path + bpmodify -w -m $module -property arch.arm64.hwasan.src -str $hwasan_dir/$module.a $bp_path + done +else + if [[ ! -f "$bp_org_path" ]]; then + echo Nothing to restore. Try without the \"restore\" option. + exit 1 + fi + mv -f $bp_org_path $bp_path + echo "$bp_path" restored +fi + +exit