| Index: build/config/sanitizers/generate_asan_runtime_stubs.py
|
| diff --git a/build/config/sanitizers/generate_asan_runtime_stubs.py b/build/config/sanitizers/generate_asan_runtime_stubs.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..edbd5c46d07a06e082812a8b9a37a1cdb7bdbc73
|
| --- /dev/null
|
| +++ b/build/config/sanitizers/generate_asan_runtime_stubs.py
|
| @@ -0,0 +1,83 @@
|
| +# Copyright 2016 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.
|
| +
|
| +import optparse
|
| +import os
|
| +import subprocess
|
| +import sys
|
| +
|
| +def GenerateASanRuntimeStubs(asan_dylib, output_file):
|
| + symbols = _GetSymbolsToStub(asan_dylib)
|
| + _WriteStubsFile(symbols, output_file)
|
| +
|
| +
|
| +def _GetSymbolsToStub(asan_dylib):
|
| + nm = ['xcrun', 'nm', '-j', '-g', '-U', asan_dylib]
|
| + output = subprocess.check_output(nm)
|
| + return output.strip().split('\n')
|
| +
|
| +
|
| +def _WriteStubsFile(symbols_to_stub, output_file):
|
| + #symbols_to_stub = [s[1:] for s in symbols_to_stub]
|
| + resolvers = [_STUB_TEMPLATE % {'name': name} for name in symbols_to_stub]
|
| + initializers = [_INITIALIZER_TEMPLATE % {'name': name} for name in symbols_to_stub]
|
| + contents = _FILE_TEMPLATE % {'resolvers': ''.join(resolvers),
|
| + 'initializers': ''.join(initializers)}
|
| + with open(output_file, 'w') as f:
|
| + f.write(contents)
|
| +
|
| +
|
| +def Main():
|
| + parser = optparse.OptionParser(
|
| + usage='%prog path/libclang_rt.asan_osx_dynamic.dylib path/gen/file.c')
|
| + opts, args = parser.parse_args()
|
| + if len(args) != 2:
|
| + parser.error('invalid arguments')
|
| +
|
| + GenerateASanRuntimeStubs(*args)
|
| + return 0
|
| +
|
| +
|
| +_FILE_TEMPLATE = """// Copyright 2016 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.
|
| +
|
| +// NOTICE: This file is generated by:
|
| +// build/config/sanitizers/generate_asan_runtime_stubs.py.
|
| +
|
| +#include <dlfcn.h>
|
| +#include <stdlib.h>
|
| +#include <stdio.h>
|
| +
|
| +%(resolvers)s
|
| +
|
| +static bool did_initialize = []() {
|
| + printf("IN INITIALIZER RESOLVER\\n");
|
| + void* library = dlopen(getenv("CHROMIUM_ASAN"), RTLD_LAZY);
|
| + if (!library)
|
| + return false;
|
| +
|
| + %(initializers)s
|
| + return true;
|
| +}();
|
| +
|
| +"""
|
| +
|
| +_INITIALIZER_TEMPLATE = """
|
| + ptr_%(name)s = dlsym(library, "%(name)s");
|
| +"""
|
| +
|
| +
|
| +_STUB_TEMPLATE = """
|
| +void* ptr_%(name)s = nullptr;
|
| +
|
| +__asm__(".globl %(name)s;"
|
| + "%(name)s:"
|
| + "movq _ptr_%(name)s(%%rip), %%rax;"
|
| + "jmpq *%%rax");
|
| +"""
|
| +
|
| +
|
| +if __name__ == '__main__':
|
| + sys.exit(Main())
|
|
|