3 import sys, os, shutil, subprocess, glob, re
5 builddir = os.getenv ('builddir', os.path.dirname (__file__))
6 libs = os.getenv ('libs', '.libs')
8 objdump = os.getenv ('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, '**', 'hb*.o'), recursive=True)
19 print ('check-static-inits.py: object files not found; skipping test')
26 result = subprocess.run(objdump.split () + ['-t', obj], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
29 if result.stderr.find (b'not recognized') != -1:
30 # https://github.com/harfbuzz/harfbuzz/issues/3019
31 print ('objdump %s returned "not recognized", skipping' % obj)
33 print ('objdump %s returned error:\n%s' % (obj, result.stderr.decode ('utf-8')))
36 result = result.stdout.decode ('utf-8')
38 # Checking that no object file has static initializers
39 for l in re.findall (r'^.*\.[cd]tors.*$', result, re.MULTILINE):
40 if not re.match (r'.*\b0+\b', l):
41 print ('Ouch, %s has static initializers/finalizers' % obj)
44 # Checking that no object file has lazy static C++ constructors/destructors or other such stuff
45 if ('__cxa_' in result) and ('__ubsan_handle' not in result):
46 print ('Ouch, %s has lazy static C++ constructors/destructors or other such stuff' % obj)
51 sys.exit (stat if tested else 77)