Skip to content

Commit b2b0322

Browse files
committed
[DFSan] Add option to specify individual library files, and an option to exit with an error code if any library file was not found.
Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D126336
1 parent 9426df9 commit b2b0322

File tree

1 file changed

+54
-24
lines changed

1 file changed

+54
-24
lines changed

compiler-rt/lib/dfsan/scripts/build-libc-list.py

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,40 +54,70 @@ def defined_function_list(object):
5454
help='path to libstdc++ DSO directory',
5555
default='/usr/lib/x86_64-linux-gnu')
5656

57+
p.add_option('--only-explicit-files', action='store_true',
58+
dest='only_explicit_files', default=False,
59+
help='Only process --lib-file, not the default libc libraries.')
60+
p.add_option('--lib-file', action='append', metavar='PATH',
61+
help='Specific library files to add.',
62+
default=[])
63+
64+
p.add_option('--error-missing-lib', action='store_true',
65+
help='Make this script exit with an error code if any library is missing.',
66+
dest='error_missing_lib', default=False)
67+
5768
(options, args) = p.parse_args()
5869

59-
libs = [os.path.join(options.libc_dso_path, name) for name in
60-
['ld-linux-x86-64.so.2',
61-
'libanl.so.1',
62-
'libBrokenLocale.so.1',
63-
'libcidn.so.1',
64-
'libcrypt.so.1',
65-
'libc.so.6',
66-
'libdl.so.2',
67-
'libm.so.6',
68-
'libnsl.so.1',
69-
'libpthread.so.0',
70-
'libresolv.so.2',
71-
'librt.so.1',
72-
'libthread_db.so.1',
73-
'libutil.so.1']]
74-
libs += [os.path.join(options.libc_archive_path, name) for name in
75-
['libc_nonshared.a',
76-
'libpthread_nonshared.a']]
77-
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'))
80-
81-
if options.with_libstdcxx:
82-
libs.append(os.path.join(options.libstdcxx_dso_path, 'libstdc++.so.6'))
70+
def build_libs_list():
71+
libs = [os.path.join(options.libc_dso_path, name) for name in
72+
['ld-linux-x86-64.so.2',
73+
'libanl.so.1',
74+
'libBrokenLocale.so.1',
75+
'libcidn.so.1',
76+
'libcrypt.so.1',
77+
'libc.so.6',
78+
'libdl.so.2',
79+
'libm.so.6',
80+
'libnsl.so.1',
81+
'libpthread.so.0',
82+
'libresolv.so.2',
83+
'librt.so.1',
84+
'libthread_db.so.1',
85+
'libutil.so.1']]
86+
libs += [os.path.join(options.libc_archive_path, name) for name in
87+
['libc_nonshared.a',
88+
'libpthread_nonshared.a']]
89+
90+
libs.append(os.path.join(options.libgcc_dso_path, 'libgcc_s.so.1'))
91+
libs.append(os.path.join(options.libgcc_archive_path, 'libgcc.a'))
92+
93+
if options.with_libstdcxx:
94+
libs.append(os.path.join(options.libstdcxx_dso_path, 'libstdc++.so.6'))
8395

96+
return libs
97+
98+
libs = []
99+
if options.only_explicit_files:
100+
libs = options.lib_file
101+
if not libs:
102+
print >> sys.stderr, 'No libraries provided.'
103+
exit(1)
104+
else:
105+
libs = build_libs_list()
106+
libs.extend(options.lib_file)
107+
108+
missing_lib = False
84109
functions = []
85110
for l in libs:
86111
if os.path.exists(l):
87112
functions += defined_function_list(l)
88113
else:
114+
missing_lib = True
89115
print >> sys.stderr, 'warning: library %s not found' % l
90116

117+
if options.error_missing_lib and missing_lib:
118+
print >> sys.stderr, 'Exiting with failure code due to missing library.'
119+
exit(1)
120+
91121
functions = list(set(functions))
92122
functions.sort()
93123

0 commit comments

Comments
 (0)