3 import sys, os, shutil, subprocess, glob, re
5 builddir = os.environ.get ('builddir', os.path.dirname (__file__))
6 libs = os.environ.get ('libs', '.libs')
8 objdump = shutil.which ('objdump')
10 print ('check-static-inits.py: \'ldd\' not found; skipping test')
13 if sys.version_info < (3, 5):
14 print ('check-static-inits.py: needs python 3.5 for recursive support in glob')
17 OBJS = glob.glob (os.path.join (builddir, libs, '**', '*.o'), recursive=True)
19 print ('check-static-inits.py: object files not found; skipping test')
25 result = subprocess.check_output ([objdump, '-t', obj]).decode ('utf-8')
27 # Checking that no object file has static initializers
28 for l in re.findall (r'^.*\.[cd]tors.*$', result, re.MULTILINE):
29 if not re.match (r'.*\b0+\b', l):
30 print ('Ouch, %s has static initializers/finalizers' % obj)
33 # Checking that no object file has lazy static C++ constructors/destructors or other such stuff
34 if ('__cxa_' in result) and ('__ubsan_handle' not in result):
35 print ('Ouch, %s has lazy static C++ constructors/destructors or other such stuff' % obj)