Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: build/config/sanitizers/generate_asan_runtime_stubs.py

Issue 2187063003: [Mac/GN] Use a special .symbol_resolver to help load the ASan dynamic library. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Static symbol stubs Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/config/sanitizers/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import optparse
6 import os
7 import subprocess
8 import sys
9
10 def GenerateASanRuntimeStubs(asan_dylib, output_file):
11 symbols = _GetSymbolsToStub(asan_dylib)
12 _WriteStubsFile(symbols, output_file)
13
14
15 def _GetSymbolsToStub(asan_dylib):
16 nm = ['xcrun', 'nm', '-j', '-g', '-U', asan_dylib]
17 output = subprocess.check_output(nm)
18 return output.strip().split('\n')
19
20
21 def _WriteStubsFile(symbols_to_stub, output_file):
22 #symbols_to_stub = [s[1:] for s in symbols_to_stub]
23 resolvers = [_STUB_TEMPLATE % {'name': name} for name in symbols_to_stub]
24 initializers = [_INITIALIZER_TEMPLATE % {'name': name} for name in symbols_to_ stub]
25 contents = _FILE_TEMPLATE % {'resolvers': ''.join(resolvers),
26 'initializers': ''.join(initializers)}
27 with open(output_file, 'w') as f:
28 f.write(contents)
29
30
31 def Main():
32 parser = optparse.OptionParser(
33 usage='%prog path/libclang_rt.asan_osx_dynamic.dylib path/gen/file.c')
34 opts, args = parser.parse_args()
35 if len(args) != 2:
36 parser.error('invalid arguments')
37
38 GenerateASanRuntimeStubs(*args)
39 return 0
40
41
42 _FILE_TEMPLATE = """// Copyright 2016 The Chromium Authors. All rights reserved.
43 // Use of this source code is governed by a BSD-style license that can be
44 // found in the LICENSE file.
45
46 // NOTICE: This file is generated by:
47 // build/config/sanitizers/generate_asan_runtime_stubs.py.
48
49 #include <dlfcn.h>
50 #include <stdlib.h>
51 #include <stdio.h>
52
53 %(resolvers)s
54
55 static bool did_initialize = []() {
56 printf("IN INITIALIZER RESOLVER\\n");
57 void* library = dlopen(getenv("CHROMIUM_ASAN"), RTLD_LAZY);
58 if (!library)
59 return false;
60
61 %(initializers)s
62 return true;
63 }();
64
65 """
66
67 _INITIALIZER_TEMPLATE = """
68 ptr_%(name)s = dlsym(library, "%(name)s");
69 """
70
71
72 _STUB_TEMPLATE = """
73 void* ptr_%(name)s = nullptr;
74
75 __asm__(".globl %(name)s;"
76 "%(name)s:"
77 "movq _ptr_%(name)s(%%rip), %%rax;"
78 "jmpq *%%rax");
79 """
80
81
82 if __name__ == '__main__':
83 sys.exit(Main())
OLDNEW
« no previous file with comments | « build/config/sanitizers/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698