upload_system_symbols.sh
1 #!/bin/bash 2 3 # Copyright 2023 Google LLC 4 # 5 # Redistribution and use in source and binary forms, with or without 6 # modification, are permitted provided that the following conditions are 7 # met: 8 # 9 # * Redistributions of source code must retain the above copyright 10 # notice, this list of conditions and the following disclaimer. 11 # * Redistributions in binary form must reproduce the above 12 # copyright notice, this list of conditions and the following disclaimer 13 # in the documentation and/or other materials provided with the 14 # distribution. 15 # * Neither the name of Google LLC nor the names of its 16 # contributors may be used to endorse or promote products derived from 17 # this software without specific prior written permission. 18 # 19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31 # Finds the dyld_shared_cache on a system, extracts it, and dumps the symbols 32 # in Breakpad format to the directory passed as the first argument 33 # The script must be in the same directory as `dump_syms`, 34 # `upload_system_symbols` and `dsc_extractor` binaries. 35 # Exits with 0 if all supported architectures for this OS version were found and 36 # dumped, and nonzero otherwise. 37 38 set -ex 39 40 if [[ $# -ne 1 ]]; then 41 echo "usage: $0 <destination_directory>" >& 2 42 exit 1 43 fi 44 45 destination_dir="$1" 46 47 dir="$(dirname "$0")" 48 dir="$(cd "${dir}"; pwd)" 49 major_version=$(sw_vers -productVersion | cut -d . -f 1) 50 if [[ "${major_version}" -lt 13 ]]; then 51 dsc_directory="/System/Library/dyld" 52 else 53 dsc_directory="/System/Volumes/Preboot/Cryptexes/OS/System/Library/dyld" 54 fi 55 56 working_dir=$(mktemp -d) 57 mkdir "${destination_dir}" 58 trap 'rm -rf "${working_dir}" "${destination_dir}"' EXIT 59 60 architectures=(x86_64h) 61 missing_architectures=() 62 # macOS >= 13 on arm64 still has a x86_64 cache for Rosetta. 63 if [[ "${major_version}" -lt 13 ]] || [[ $(uname -p) == "arm" ]]; then 64 architectures+=( x86_64 ) 65 fi 66 if [[ "${major_version}" -ge 11 ]]; then 67 architectures+=( arm64e ) 68 fi 69 70 for arch in "${architectures[@]}"; do 71 cache="${dsc_directory}/dyld_shared_cache_${arch}" 72 if [[ ! -f "${cache}" ]]; then 73 missing_architectures+=("${arch}") 74 continue 75 fi 76 "${dir}/dsc_extractor" \ 77 "${cache}" \ 78 "${working_dir}/${arch}" 79 "${dir}/upload_system_symbols" \ 80 --breakpad-tools="${dir}" \ 81 --system-root="${working_dir}/${arch}" \ 82 --dump-to="${destination_dir}" 83 done 84 if [[ "${#missing_architectures[@]}" -eq "${#architectures[@]}" ]]; then 85 echo "Couldn't locate dyld_shared_cache for any architectures" >& 2 86 echo "in ${dsc_directory}. Exiting." >& 2 87 exit 1 88 fi 89 90 rm -rf "${working_dir}" 91 # We have results now, so let's keep `destination_dir`. 92 trap '' EXIT 93 94 "${dir}/upload_system_symbols" \ 95 --breakpad-tools="${dir}" \ 96 --system-root=/ \ 97 --dump-to="${destination_dir}" 98 99 set +x 100 echo 101 echo "Dumped!" 102 echo "To upload, run:" 103 echo 104 echo "'${dir}/upload_system_symbols'" \\ 105 echo " --breakpad-tools='${dir}'" \\ 106 echo " --api-key=<YOUR API KEY>" \\ 107 echo " --upload-from='${destination_dir}'" 108 109 if [[ "${#missing_architectures[@]}" -gt 0 ]]; then 110 echo "dyld_shared_cache not found for architecture(s):" >& 2 111 echo " " "${missing_architectures[@]}" >& 2 112 echo "You'll need to get symbols for them elsewhere." >& 2 113 exit 1 114 fi