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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/config/sanitizers/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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())
« 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