diff options
author | dim <dim@FreeBSD.org> | 2014-11-06 22:49:13 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2014-11-06 22:49:13 +0000 |
commit | c3f67e1dc21025f1026cbf72628b19fb37f7b53d (patch) | |
tree | 3467f3372c1195b1546172d89af2205a50b1866d /lib/sanitizer_common/scripts/gen_dynamic_list.py | |
parent | 2f7fa77a0a85c00fd0cce298851e9577b98ccfe8 (diff) | |
download | FreeBSD-src-c3f67e1dc21025f1026cbf72628b19fb37f7b53d.zip FreeBSD-src-c3f67e1dc21025f1026cbf72628b19fb37f7b53d.tar.gz |
Import compiler-rt release_34 branch r197381.
https://llvm.org/svn/llvm-project/compiler-rt/branches/release_34@197381
Diffstat (limited to 'lib/sanitizer_common/scripts/gen_dynamic_list.py')
-rwxr-xr-x | lib/sanitizer_common/scripts/gen_dynamic_list.py | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/lib/sanitizer_common/scripts/gen_dynamic_list.py b/lib/sanitizer_common/scripts/gen_dynamic_list.py new file mode 100755 index 0000000..32ba922 --- /dev/null +++ b/lib/sanitizer_common/scripts/gen_dynamic_list.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python +#===- lib/sanitizer_common/scripts/gen_dynamic_list.py ---------------------===# +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +#===------------------------------------------------------------------------===# +# +# Generates the list of functions that should be exported from sanitizer +# runtimes. The output format is recognized by --dynamic-list linker option. +# Usage: +# gen_dynamic_list.py libclang_rt.*san*.a [ files ... ] +# +#===------------------------------------------------------------------------===# +import os +import re +import subprocess +import sys + +new_delete = set(['_ZdaPv', '_ZdaPvRKSt9nothrow_t', + '_ZdlPv', '_ZdlPvRKSt9nothrow_t', + '_Znam', '_ZnamRKSt9nothrow_t', + '_Znwm', '_ZnwmRKSt9nothrow_t']) + +versioned_functions = set(['memcpy', 'pthread_attr_getaffinity_np', + 'pthread_cond_broadcast', + 'pthread_cond_destroy', 'pthread_cond_init', + 'pthread_cond_signal', 'pthread_cond_timedwait', + 'pthread_cond_wait', 'realpath', + 'sched_getaffinity']) + +def get_global_functions(library): + functions = [] + nm_proc = subprocess.Popen(['nm', library], stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + nm_out = nm_proc.communicate()[0].split('\n') + if nm_proc.returncode != 0: + raise subprocess.CalledProcessError(nm_proc.returncode, 'nm') + for line in nm_out: + cols = line.split(' ') + if (len(cols) == 3 and cols[1] in ('T', 'W')) : + functions.append(cols[2]) + return functions + +def main(argv): + result = [] + + library = argv[1] + all_functions = get_global_functions(library) + function_set = set(all_functions) + for func in all_functions: + # Export new/delete operators. + if func in new_delete: + result.append(func) + continue + # Export interceptors. + match = re.match('__interceptor_(.*)', func) + if match: + result.append(func) + # We have to avoid exporting the interceptors for versioned library + # functions due to gold internal error. + orig_name = match.group(1) + if orig_name in function_set and orig_name not in versioned_functions: + result.append(orig_name) + continue + # Export sanitizer interface functions. + if re.match('__sanitizer_(.*)', func): + result.append(func) + + # Additional exported functions from files. + for fname in argv[2:]: + f = open(fname, 'r') + for line in f: + result.append(line.rstrip()) + # Print the resulting list in the format recognized by ld. + print '{' + result.sort() + for f in result: + print ' ' + f + ';' + print '};' + +if __name__ == '__main__': + main(sys.argv) |