Commit 26561f3f authored by Sajjad Mirza's avatar Sajjad Mirza Committed by Commit Bot

Use a whitelist for Mac OS static initializer checks.

When a dsym is present we can get the file that each initializer was from
and compare against a list of accepted files. This helps support code
coverage on the CQ, which adds 2 additional static initializers.

When a dsym is not available, we fall back to counting how many static
initializers there are and comparing that against a hardcoded number.

Bug: 1059432

Change-Id: I6a1df68371a34724822343198afb14fdd1f9cff8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2106349
Commit-Queue: Sajjad Mirza <sajjadm@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751397}
parent 6372ff56
...@@ -26,13 +26,18 @@ _LINUX_SI_FILE_WHITELIST = { ...@@ -26,13 +26,18 @@ _LINUX_SI_FILE_WHITELIST = {
} }
_LINUX_SI_FILE_WHITELIST['nacl_helper'] = _LINUX_SI_FILE_WHITELIST['chrome'] _LINUX_SI_FILE_WHITELIST['nacl_helper'] = _LINUX_SI_FILE_WHITELIST['chrome']
# TODO: Convert Mac to use the whitelist, but need to first modify # Mac can use a whitelist when a dsym is available, otherwise we will fall back
# //tools/mac/dump-static-initializers.py to have the same stdout format as # to checking the count.
# //tools/linux/dump-static-initializers.py. _MAC_SI_FILE_WHITELIST = [
# 'InstrProfilingRuntime.cpp', # Only in coverage builds, not in production.
'sysinfo.cc', # Only in coverage builds, not in production.
'iostream.cpp', # Used to setup std::cin/cout/cerr.
]
# A static initializer is needed on Mac for libc++ to set up std::cin/cout/cerr # A static initializer is needed on Mac for libc++ to set up std::cin/cout/cerr
# before main() runs. # before main() runs. Coverage CQ will have a dsym so only iostream.cpp needs
EXPECTED_MAC_SI_COUNT = 1 # to be counted here.
FALLBACK_EXPECTED_MAC_SI_COUNT = 1
def run_process(command): def run_process(command):
...@@ -73,11 +78,7 @@ def main_mac(src_dir): ...@@ -73,11 +78,7 @@ def main_mac(src_dir):
si_count = int(initializers_s, 16) / word_size si_count = int(initializers_s, 16) / word_size
# Print the list of static initializers. # Print the list of static initializers.
if si_count > EXPECTED_MAC_SI_COUNT: if si_count > 0:
print('Expected <= %d static initializers in %s, but found %d' %
(EXPECTED_MAC_SI_COUNT, chromium_framework_executable, si_count))
ret = 1
# First look for a dSYM to get information about the initializers. If # First look for a dSYM to get information about the initializers. If
# one is not present, check if there is an unstripped copy of the build # one is not present, check if there is an unstripped copy of the build
# output. # output.
...@@ -87,8 +88,16 @@ def main_mac(src_dir): ...@@ -87,8 +88,16 @@ def main_mac(src_dir):
mac_tools_path, 'dump-static-initializers.py') mac_tools_path, 'dump-static-initializers.py')
stdout = run_process( stdout = run_process(
[dump_static_initializers, chromium_framework_dsym]) [dump_static_initializers, chromium_framework_dsym])
for line in stdout:
if re.match('0x[0-9a-f]+', line) and not any(
f in line for f in _MAC_SI_FILE_WHITELIST):
ret = 1
print 'Found invalid static initializer: {}'.format(line)
print stdout print stdout
else: elif si_count > FALLBACK_EXPECTED_MAC_SI_COUNT:
print('Expected <= %d static initializers in %s, but found %d' %
(FALLBACK_EXPECTED_MAC_SI_COUNT, chromium_framework_executable,
si_count))
show_mod_init_func = os.path.join(mac_tools_path, show_mod_init_func = os.path.join(mac_tools_path,
'show_mod_init_func.py') 'show_mod_init_func.py')
args = [show_mod_init_func] args = [show_mod_init_func]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment