#!/bin/bash # Copyright (c) 2009 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # Verifies that no global text symbols are present in a Mach-O file # (MACH_O_FILE) at an address higher than the address of a specific symbol # (LAST_SYMBOL). If LAST_SYMBOL is not found in MACH_O_FILE or if symbols # are present with addresses higher than LAST_SYMBOL's address, an error # message is printed to stderr, and the script will exit nonzero. # # This script can be used to verify that all of the global text symbols in # a Mach-O file are accounted for in an order file. if [ ${#} -ne 2 ] ; then echo "usage: ${0} LAST_SYMBOL MACH_O_FILE" >& 2 exit 1 fi LAST_SYMBOL=${1} MACH_O_FILE=${2} SYMBOLS=$(nm -fgjn -s __TEXT __text "${MACH_O_FILE}") if [ ${?} -ne 0 ] || [ -z "${SYMBOLS}" ] ; then echo "${0}: no symbols in ${MACH_O_FILE}" >& 2 exit 1 fi LAST_SYMBOLS=$(grep -A 100 -Fx "${LAST_SYMBOL}" <<< "${SYMBOLS}") if [ ${?} -ne 0 ] || [ -z "${LAST_SYMBOLS}" ] ; then echo "${0}: symbol ${LAST_SYMBOL} not found in ${MACH_O_FILE}" >& 2 exit 1 fi UNORDERED_SYMBOLS=$(grep -Fvx "${LAST_SYMBOL}" <<< "${LAST_SYMBOLS}") if [ ${?} -eq 0 ] || [ -n "${UNORDERED_SYMBOLS}" ] ; then echo "${0}: unordered symbols in ${MACH_O_FILE}:" >& 2 echo "${UNORDERED_SYMBOLS}" >& 2 exit 1 fi exit 0