diff --git a/compiler-rt/lib/hwasan/scripts/hwasan_symbolize b/compiler-rt/lib/hwasan/scripts/hwasan_symbolize index f73ea1783d758f..3aba1875d19a2e 100755 --- a/compiler-rt/lib/hwasan/scripts/hwasan_symbolize +++ b/compiler-rt/lib/hwasan/scripts/hwasan_symbolize @@ -21,6 +21,9 @@ import sys import string import subprocess import argparse +import mmap +import struct +import os if sys.version_info.major < 3: # Simulate Python 3.x behaviour of defaulting to UTF-8 for print. This is @@ -31,6 +34,71 @@ if sys.version_info.major < 3: last_access_address = None last_access_tag = None +# Below, a parser for a subset of ELF. It only supports 64 bit, little-endian, +# and only parses what is necessary to find the build ids. It uses a memoryview +# into an mmap to avoid copying. +Ehdr_size = 64 +e_shnum_offset = 60 +e_shoff_offset = 40 + +Shdr_size = 64 +sh_type_offset = 4 +sh_offset_offset = 24 +sh_size_offset = 32 +SHT_NOTE = 7 + +Nhdr_size = 12 +NT_GNU_BUILD_ID = 3 + +def align_up(size, alignment): + return (size + alignment - 1) & ~(alignment - 1) + +def handle_Nhdr(mv, sh_size): + offset = 0 + while offset < sh_size: + n_namesz, n_descsz, n_type = struct.unpack_from(' 0: print("%s#%s%s%s in %s" % (match.group(1), match.group(2), @@ -210,6 +292,7 @@ parser.add_argument('-v', action='store_true') parser.add_argument('--ignore-tags', action='store_true') parser.add_argument('--symbols', action='append') parser.add_argument('--source', action='append') +parser.add_argument('--index', action='store_true') parser.add_argument('--symbolizer') parser.add_argument('args', nargs=argparse.REMAINDER) args = parser.parse_args() @@ -297,6 +380,8 @@ if args.v: symbolizer = Symbolizer(symbolizer_path, binary_prefixes, paths_to_cut) symbolizer.enable_logging(args.d) +if args.index: + symbolizer.build_index() for line in sys.stdin: if sys.version_info.major < 3: