summaryrefslogtreecommitdiffstats
path: root/chrome/tools/build/mac/verify_order
blob: d10ca9d4b33802a65244b12cebd12fd0047c173f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/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.
#
# Also check that the file does not depend on either of libstdc++ or libc++.

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 -gjn "${MACH_O_FILE}" -s __TEXT __text)
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

LIBS=$(otool -L "${MACH_O_FILE}")
if [ ${?} -ne 0 ] ; then
  echo "${0}: failed to get libraries in ${MACH_O_FILE}" >& 2
  exit 1
fi
if grep -Fq libstdc++ <<< ${LIBS} ; then
  echo "${0}: ${MACH_O_FILE} depends on libstdc++" >& 2
  exit 1
fi
if grep -Fq libc++ <<< ${LIBS} ; then
  echo "${0}: ${MACH_O_FILE} depends on libc++" >& 2
  exit 1
fi

exit 0