2 #===- lib/dfsan/scripts/build-libc-list.py ---------------------------------===#
4 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 # See https://llvm.org/LICENSE.txt for license information.
6 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 #===------------------------------------------------------------------------===#
9 # The purpose of this script is to identify every function symbol in a set of
10 # libraries (in this case, libc and libgcc) so that they can be marked as
11 # uninstrumented, thus allowing the instrumentation pass to treat calls to those
12 # functions correctly.
17 from optparse
import OptionParser
19 def defined_function_list(object):
21 readelf_proc
= subprocess
.Popen(['readelf', '-s', '-W', object],
22 stdout
=subprocess
.PIPE
)
23 readelf
= readelf_proc
.communicate()[0].split('\n')
24 if readelf_proc
.returncode
!= 0:
25 raise subprocess
.CalledProcessError(readelf_proc
.returncode
, 'readelf')
27 if (line
[31:35] == 'FUNC' or line
[31:36] == 'IFUNC') and \
28 line
[39:44] != 'LOCAL' and \
30 function_name
= line
[59:].split('@')[0]
31 functions
.append(function_name
)
36 p
.add_option('--libc-dso-path', metavar
='PATH',
37 help='path to libc DSO directory',
38 default
='/lib/x86_64-linux-gnu')
39 p
.add_option('--libc-archive-path', metavar
='PATH',
40 help='path to libc archive directory',
41 default
='/usr/lib/x86_64-linux-gnu')
43 p
.add_option('--libgcc-dso-path', metavar
='PATH',
44 help='path to libgcc DSO directory',
45 default
='/lib/x86_64-linux-gnu')
46 p
.add_option('--libgcc-archive-path', metavar
='PATH',
47 help='path to libgcc archive directory',
48 default
='/usr/lib/gcc/x86_64-linux-gnu/4.6')
50 p
.add_option('--with-libstdcxx', action
='store_true',
51 dest
='with_libstdcxx',
52 help='include libstdc++ in the list (inadvisable)')
53 p
.add_option('--libstdcxx-dso-path', metavar
='PATH',
54 help='path to libstdc++ DSO directory',
55 default
='/usr/lib/x86_64-linux-gnu')
57 (options
, args
) = p
.parse_args()
59 libs
= [os
.path
.join(options
.libc_dso_path
, name
) for name
in
60 ['ld-linux-x86-64.so.2',
62 'libBrokenLocale.so.1',
74 libs
+= [os
.path
.join(options
.libc_archive_path
, name
) for name
in
76 'libpthread_nonshared.a']]
78 libs
.append(os
.path
.join(options
.libgcc_dso_path
, 'libgcc_s.so.1'))
79 libs
.append(os
.path
.join(options
.libgcc_archive_path
, 'libgcc.a'))
81 if options
.with_libstdcxx
:
82 libs
.append(os
.path
.join(options
.libstdcxx_dso_path
, 'libstdc++.so.6'))
87 functions
+= defined_function_list(l
)
89 print >> sys
.stderr
, 'warning: library %s not found' % l
91 functions
= list(set(functions
))
95 print 'fun:%s=uninstrumented' % f