1#! /usr/bin/env python3 2# Copyright 2024 The Chromium Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import argparse 7import pathlib 8 9 10def _generate(arch): 11 return f"""\ 12#!/system/bin/sh 13# See: https://github.com/google/sanitizers/wiki/AddressSanitizerOnAndroid/\ 1401f8df1ac1a447a8475cdfcb03e8b13140042dbd#running-with-wrapsh-recommended 15HERE="$(cd "$(dirname "$0")" && pwd)" 16# Options suggested by wiki docs: 17_ASAN_OPTIONS="log_to_syslog=false,allow_user_segv_handler=1" 18# Chromium-specific option (supposedly for graphics drivers): 19_ASAN_OPTIONS="$_ASAN_OPTIONS,strict_memcmp=0,use_sigaltstack=1" 20_LD_PRELOAD="$HERE/libclang_rt.asan-{arch}-android.so" 21log -t cr_wrap.sh -- "Launching with ASAN enabled." 22log -t cr_wrap.sh -- "LD_PRELOAD=$_LD_PRELOAD" 23log -t cr_wrap.sh -- "ASAN_OPTIONS=$_ASAN_OPTIONS" 24log -t cr_wrap.sh -- "Command: $0 $@" 25# Export LD_PRELOAD after running "log" commands to not risk it affecting 26# them. 27export LD_PRELOAD=$_LD_PRELOAD 28export ASAN_OPTIONS=$_ASAN_OPTIONS 29exec "$@" 30""" 31 32 33def main(): 34 parser = argparse.ArgumentParser() 35 parser.add_argument('--arch', required=True) 36 parser.add_argument('--output', required=True) 37 args = parser.parse_args() 38 39 pathlib.Path(args.output).write_text(_generate(args.arch)) 40 41 42if __name__ == '__main__': 43 main() 44